Post

Replies

Boosts

Views

Activity

Reply to Send Notification when Ble Device is discovered.
Launching an iOS app from a terminated state to the background based solely on a Bluetooth Low Energy (BLE) device being scanned is not straightforward due to iOS limitations. The app lifecycle and background execution modes in iOS are tightly controlled for battery and privacy reasons, and there are limited options for waking up an app from a terminated state. However, there are a few potential approaches you can consider: Core Bluetooth Background Processing: iOS provides some background processing capabilities for BLE through the Core Bluetooth framework. You can set up your app to act as a BLE central and listen for advertisements from your BLE device. When a device is discovered, your app can receive a callback even if it's in the background. You can then use this opportunity to perform some background tasks, like showing a local notification to the user. Keep in mind that this approach doesn't directly launch your app from a terminated state to the background. Instead, it allows your app to respond to BLE peripheral advertisements when it's already in the background. Remote Notifications: If you want to notify users about BLE device events, consider using remote notifications (push notifications). When your BLE device is in range, it can trigger a remote server to send a push notification to the user's device. Tapping on the notification can then launch your app. This approach allows you to wake up your app from a terminated state when the user interacts with the notification. However, it relies on a network connection and a server to send notifications. iBeacon: As you mentioned, you've explored using iBeacon. While iBeacon can help your app launch in the background when an iBeacon region is entered, it may not be the most efficient approach for your use case, as it's primarily designed for proximity detection. Background App Refresh: If your app has the "Background App Refresh" permission from the user, you can periodically wake up in the background to scan for BLE devices. This doesn't directly launch your app from a terminated state, but it allows you to perform BLE scans periodically when in the background. Remember that for any background processing, you should consider the impact on battery life and user privacy. iOS places strict limitations on how often and for what purposes an app can run in the background to ensure a positive user experience.
Oct ’23
Reply to NavigationSplitView detail view with safearea
I understand that you're still facing issues with the green button not being clickable, even after using .contentShape(Rectangle()). It seems like the safe area is causing some constraints on the button's clickability. To address this, you can try adjusting the frame of your MasterdataDetailView to make sure the button is not within the safe area. Here's an example of how you can do this: MasterdataDetailView() .frame(maxWidth: .infinity, maxHeight: .infinity) By setting the frame to use the full available width and height (maxWidth: .infinity, maxHeight: .infinity), you ensure that the button is positioned outside the safe area, making it clickable. If this still doesn't resolve the issue, you may need to inspect the layout of your MasterdataDetailView and its parent views to identify any conflicting constraints or safe area insets that might be affecting the button's clickability.
Oct ’23
Reply to How is "Navigator" implemented in the session's video?
In SwiftUI, you typically use NavigationView and NavigationLink for navigation between screens or views. While it's not recommended to use intents for general navigation within your app, you can implement basic navigation like this: Import SwiftUI: import SwiftUI Create your views. For example, you might have two views, ViewA and ViewB: struct ViewA: View { var body: some View { NavigationView { VStack { Text("View A") NavigationLink("Go to View B", destination: ViewB()) } } } } struct ViewB: View { var body: some View { Text("View B") } } In your @main App struct, set the ViewA as the initial view: @main struct YourApp: App { var body: some Scene { WindowGroup { ViewA() } } } Run your app. You'll see that you can navigate from View A to View B by tapping "Go to View B." This is a basic example of navigation in SwiftUI. If you have more complex navigation needs, you can use NavigationView, NavigationLink, and the @State property wrapper to manage the navigation state within your views. Intents are typically used for handling app-specific actions triggered by Siri or other external events rather than general navigation within your app.
Oct ’23
Reply to XML signing in Mac Os using swift
In Swift, you can use the Security framework to perform XML digital signing with RSA. Here are the steps to sign an XML file using the enveloped signature approach in Swift: Import the necessary frameworks: import Foundation import Security import SecurityFoundation import SwiftXML Load your XML content from a file or create it programmatically. Compute the digest value using SHA-1: func computeDigestValue(data: Data) -> String { var digest = [UInt8](repeating: 0, count: Int(CC_SHA1_DIGEST_LENGTH)) data.withUnsafeBytes { _ = CC_SHA1($0.baseAddress, CC_LONG(data.count), &digest) } return Data(digest).base64EncodedString() } Create a SignedXMLDocument and add the digest value: let xmlDocument = try XMLDocument(data: yourXMLData) let signedXMLDocument = SignedXMLDocument(xmlDocument: xmlDocument) let digestValue = computeDigestValue(data: yourXMLData) try signedXMLDocument.addDigestValue(id: "", algorithm: "http://www.w3.org/2000/09/xmldsig#sha1", value: digestValue) Add the signature to the XML document: let privateKey = yourPrivateKey // Load your RSA private key here try signedXMLDocument.signWithRSA(privateKey: privateKey) Save the signed XML document: let signedXMLData = try signedXMLDocument.xmlData(prettyPrinted: true) try signedXMLData.write(to: signedXMLFileURL) This code should help you sign an XML file using the enveloped signature approach in Swift. You would need to replace yourXMLData with the XML data you want to sign and provide your RSA private key. You can use the Security framework to work with RSA keys in Swift. Please note that handling cryptographic operations like this can be complex, and you should ensure that your private key is securely managed. Additionally, consider using more secure hashing algorithms than SHA-1 for stronger security.
Oct ’23
Reply to How to use `.focusedSceneObject()` with @Observable?
The migration from .focusedSceneObject() to @Observable in SwiftUI can be achieved by using a @State property to store the focused value and then binding the focused property of the view to this @State property. Here's how you can migrate from .focusedSceneObject() to @Observable: Define an @Observable Property: Create an @Observable property that will store the focused value. This property can be of any appropriate data type, such as a String or a custom struct. For example: @Observable var focusedValue: String = "" Bind focused to the @Observable Property: Instead of using .focusedSceneObject(), you can bind the focused property of a view to your @Observable property using the $ syntax. This allows you to set and get the focused value. For example, if you were using .focusedSceneObject() like this: .focusedSceneObject(\.focusedValue) You can migrate it to @Observable like this: .focused($focusedValue) This binding connects the view's focus state to the focusedValue property. Update Usage of the Focused Value: Wherever you were using .focusedSceneObject(\.focusedValue), you can now use the focusedValue property directly. For example, if you had a Text view displaying the focused value: Text("Focused Value: \(focusedValue)") This code will still work with the focusedValue property defined in step 1. By following these steps, you can migrate from .focusedSceneObject() to @Observable while maintaining the functionality of managing the focused value in your SwiftUI view.
Oct ’23
Reply to How to override [CodingKey] to an Encoder or Decoder?
In Swift, the codingPath property is used to keep track of the coding keys as you encode or decode data using the Encoder and Decoder protocols. Typically, this property is managed automatically when you use a KeyedEncodingContainer or KeyedDecodingContainer with a struct or class that conforms to the Codable protocol. However, if you have a custom coding class and want to provide your own codingPath, you can do so. Here's how you can override the codingPath property in your custom coding class: import Foundation class MyCustomEncoder: Encoder { // Your custom implementation here var codingPath: [CodingKey] = [] // Initialize the codingPath // Rest of your Encoder implementation... } In this example, I've created a custom encoder class MyCustomEncoder that conforms to the Encoder protocol. Within this class, I've added a property codingPath and initialized it as an empty array of CodingKey. You can manipulate this array to represent the coding path as you encode data. For example, when encoding a nested container, you can push a new coding key onto the coding path, and when you exit the nested container, you can pop it off: struct MyCustomEncodingContainer: EncodingContainer { // Your custom implementation here mutating func encode(_ value: Bool, forKey key: KeyedEncodingContainer<K>.Key) throws { // Add the current key to the coding path codingPath.append(key) // Encode your value here... // Remove the current key from the coding path when done codingPath.removeLast() } // Rest of your EncodingContainer implementation... } In this way, you can manage the codingPath property manually within your custom coding class to track the hierarchy of coding keys as you encode or decode data. Remember that managing the codingPath manually can be error-prone, so it's essential to handle it carefully to ensure the correct encoding or decoding of your data.
Oct ’23
Reply to Stereo recording and audio quality
The MXSessionMode you mentioned, specifically "SpatialRecording," is related to spatial audio capture and processing, which provides a more immersive audio experience. Achieving spatial audio recording depends on several factors, including the hardware capabilities of the device, the settings of your capture session, and the audio configuration you use. To configure your capture session for spatial audio recording, you can follow these steps: Select the Right Audio Format: Ensure that you are using an audio format that supports spatial audio. You should use Audio Format Settings that allow for multi-channel audio recording. For example, you can use the AVAudioFormat with a channelCount greater than 2 to enable multi-channel audio recording. let audioSettings: [String: Any] = [ AVFormatIDKey: kAudioFormatLinearPCM, AVSampleRateKey: 44100.0, AVNumberOfChannelsKey: 4, // Set this to the number of audio channels you need (e.g., 4 for spatial audio) // Other audio settings... ] let audioFormat = AVAudioFormat(settings: audioSettings) Configure Audio Session: Set up your audio session to enable multi-channel audio recording. You can do this using AVAudioSession and configuring the category and mode properties. let audioSession = AVAudioSession.sharedInstance() do { try audioSession.setCategory(.record, mode: .videoRecording, options: .allowBluetooth) try audioSession.setActive(true) } catch { // Handle audio session configuration error } Update Capture Session: Configure your capture session to use the audio format you defined earlier and make sure you're capturing audio along with video. let captureSession = AVCaptureSession() if let audioDevice = AVCaptureDevice.default(for: .audio) { do { let audioInput = try AVCaptureDeviceInput(device: audioDevice) if captureSession.canAddInput(audioInput) { captureSession.addInput(audioInput) } } catch { // Handle audio input device error } } // Configure video capture input and output... captureSession.startRunning() Set Audio Output Settings: When configuring your audio output settings (e.g., for a movie file output), make sure you're using the audio format and settings that support spatial audio. let audioOutputSettings: [String: Any] = [ AVFormatIDKey: kAudioFormatMPEG4AAC, AVNumberOfChannelsKey: 4, // Match the channel count to the audio format // Other audio settings... ] // Set the audio settings when configuring the output... audioOutput.setAudioSettings(audioOutputSettings, for: audioConnection) Testing and Validation: Test your app on devices that support spatial audio recording, such as those with multiple microphones. Ensure that you are capturing audio from the correct microphones to achieve the desired spatial audio effect. By following these steps and configuring your capture session and audio settings appropriately, you should be able to record spatial audio with your iOS app, achieving the desired MXSessionMode of "SpatialRecording" in mediaserverd. Please note that not all iOS devices support spatial audio recording, so you should test on devices with the required hardware capabilities.
Oct ’23
Reply to Receiving OSStatus error code 268435465
The OSStatus error code 268435465 corresponds to a kVTPropertyNotSupportedErr error in the Video Toolbox framework. This error indicates that the requested property is not supported or is not available for the given video asset or configuration. Here are some common reasons why you might encounter this error and how to avoid it: Unsupported Property: Check Property Documentation: Review the documentation for the Video Toolbox property you are trying to set or retrieve. Ensure that you are using a valid and supported property key. Compatibility: Make sure that the property you are trying to use is compatible with the video asset or configuration you are working with. Some properties may only be applicable to certain video formats, encoders, or settings. Video Configuration: Valid Video Configuration: Ensure that the video configuration you are using (e.g., pixel format, codec, resolution) is compatible with the operation you are attempting. Some properties may not be supported for certain video configurations. Codec Support: Verify that the selected video codec supports the specific property you are trying to set. Not all properties are supported by all codecs. Hardware Limitations: Hardware Capabilities: Keep in mind that certain properties may depend on the hardware capabilities of the device. Some properties may only be available on specific iOS or macOS devices with certain hardware features. iOS/macOS Version: OS Compatibility: Check if the property you are trying to use is available on the iOS or macOS version you are targeting. Some properties may be introduced or deprecated in different OS versions. Property Ordering: Set Properties in the Right Order: In some cases, the order in which you set properties can matter. Make sure you are setting properties in the correct sequence, especially when configuring a complex video pipeline. Error Handling: Check for Errors: Always check the return values and error codes when working with Video Toolbox functions. If you receive a kVTPropertyNotSupportedErr error, handle it gracefully in your code and provide appropriate error messages to the user or log detailed information for debugging. Apple Documentation and Forums: Consult Apple Documentation: Refer to Apple's official documentation for Video Toolbox and related frameworks for specific guidance on working with properties and configurations. Apple Developer Forums: If you continue to encounter issues, consider searching or posting questions on the Apple Developer Forums. Developers and Apple engineers often provide insights and solutions to common problems. By following these steps and carefully reviewing the documentation for the Video Toolbox framework and the specific properties you are working with, you can often pinpoint the cause of the kVTPropertyNotSupportedErr error and take appropriate corrective actions to avoid it.
Oct ’23
Reply to Too many entries for NavigationStack
If you have multiple NavigationStacks and detailed descriptions for medications, and you need to link to details from other pages, you can still organize your code to avoid SwiftUI's NavigationLink limitation. Here's a way to achieve this: Use a ViewModel: Create a ViewModel that holds information about each medication, including its name and detailed description. struct MedicationViewModel: Identifiable { let id = UUID() let name: String let detailedDescription: String // Add any other properties you need for each medication } Create a Centralized Medication Data Source: Have a central data source that contains all the medication information. This data source can be an ObservableObject that you can pass around to different views in your app. class MedicationDataSource: ObservableObject { @Published var medications: [MedicationViewModel] = [] init() { // Initialize medications with data medications = [ MedicationViewModel(name: "Acetylsalicylsäure", detailedDescription: "Details for Acetylsalicylsäure"), MedicationViewModel(name: "Amiodaron", detailedDescription: "Details for Amiodaron"), // Add more medications and descriptions here ] } } Use NavigationLink in a Central View: In your central view, such as your Medikamente view, use a List or other UI element to display the medication names and create NavigationLinks to navigate to the detailed views. struct Medikamente: View { @ObservedObject var dataSource = MedicationDataSource() var body: some View { NavigationView { List(dataSource.medications) { medication in NavigationLink(destination: MedicationDetailView(medication: medication)) { Text(medication.name) } } .navigationTitle("Medikamente") } } } Create Detailed Views: For each medication, create a detailed view (MedicationDetailView) that takes the MedicationViewModel as a parameter and displays the detailed information. struct MedicationDetailView: View { let medication: MedicationViewModel var body: some View { VStack { Text(medication.name) Text(medication.detailedDescription) // Add more content as needed } .navigationTitle("Details") } } With this approach, you can easily add as many medications as you need without hitting SwiftUI's NavigationLink limitation. You can also navigate to detailed views from various pages in your app by sharing the MedicationDataSource. This centralizes your data and makes it more maintainable as your app grows.
Oct ’23
Reply to NavigationSplitView detail view with safearea
To make a button in the MasterdataDetailView clickable, you can try adjusting its frame or alignment to ensure it's not within the safe area. You can also use the .contentShape() modifier to extend the clickable area of the button. Here's an example of how you can modify your code: Assuming you have a Button in your MasterdataDetailView, you can modify it like this: MasterdataDetailView().ignoresSafeArea().contentShape(Rectangle()) By applying the .contentShape(Rectangle()) modifier, you are extending the clickable area of the button to the entire view, making it accessible even if it's within the safe area. If the button is still not clickable, you might need to adjust the frame or alignment of the MasterdataDetailView or its containing views to ensure that it's not obscured by the safe area. Make sure that the button is fully visible and not partially hidden within the safe area of the screen.
Oct ’23
Reply to git branch cmd launching less editor
To change the behavior of the git branch command so that it displays results on the command line rather than launching a text editor like less, you can configure the pager.branch setting in your Git configuration. You can do this by running the following command: git config --global pager.branch false This command sets the pager.branch configuration option to false, which means that Git will not use a pager (like less) for commands like git branch, and the output will be displayed directly on the command line. After running this command, when you invoke git branch, it should display the branch list directly in your terminal without launching a text editor.
Oct ’23
Reply to How to reverse the Notification (Local or Push) tap behaviour
To reverse the default behavior of notifications on iOS, where tapping opens the notification preview (interactive notification) and pressing and holding opens the app, you can achieve this by customizing the notification's content and actions. Here are the steps to implement this: Create a Custom Notification Content Extension: You'll need to create a Notification Content Extension to customize the appearance and behavior of your notifications. Follow these steps: In Xcode, go to "File" -> "New" -> "Target..." Select "Notification Content Extension" from the list. Name your extension and click "Finish." Customize the Notification Content: In your Notification Content Extension, you can customize the content of your notification. You can create a custom UI and handle interactions within this extension. Customize the Notification Actions: You can define custom notification actions for your notification. These actions can be used to open the app when pressed and held. Define these actions in your main app's code: import UserNotifications // Define custom actions let openAppAction = UNNotificationAction( identifier: "OpenAppAction", title: "Open App", options: [.foreground] ) // Create a category that includes the custom actions let notificationCategory = UNNotificationCategory( identifier: "CustomCategory", actions: [openAppAction], intentIdentifiers: [], options: [] ) // Register the category with the notification center UNUserNotificationCenter.current().setNotificationCategories([notificationCategory]) Handle Actions in the Extension: In your Notification Content Extension, you can implement code to handle the custom actions. For example, when the "Open App" action is triggered, you can open the app: func didReceive(_ notification: UNNotification) { // Handle the notification content // ... // Handle the custom actions if let action = notification.request.content.categoryIdentifier { switch action { case "CustomCategory": if notification.request.identifier == "OpenAppAction" { // Handle the "Open App" action // Open your app here } default: break } } } By following these steps, you can reverse the default behavior of notifications on iOS, making tapping open the notification preview and pressing and holding open the app. Remember to customize the notification content and actions to suit your app's specific needs.
Oct ’23
Reply to Problems submitting an App Clip with size above 15mb (for digital invocations)
It appears there might be some confusion or potential issues related to App Clip size and support for digital invocations. To address these issues and ensure your App Clip meets Apple's requirements, consider the following steps: Check Deployment Target Settings: Ensure that the App Clip target has the correct deployment target set to iOS 16.4 or later. Make sure your App Clip target doesn't have any dependencies or frameworks that have a minimum deployment target below iOS 16.4. Reduce App Clip Size: Examine the contents of your App Clip and try to reduce its size by removing any unnecessary resources, assets, or code. Review asset compression settings for images and media to minimize their size. Use asset catalogs to manage and optimize your image assets. If your App Clip contains third-party libraries or frameworks, ensure that they are stripped of unnecessary architectures and resources. Verify Asset Slicing: Confirm that asset slicing is enabled for your App Clip target. Asset slicing is a part of app thinning, and it should help reduce the size of the App Clip when it's downloaded on-demand. Digital Invocation Support: Although you mentioned you haven't found a way to specify digital invocation support, you can emphasize in your App Clip's App Store Connect description and submission notes that it is designed for digital invocation only, as specified in Apple's guidelines. Make it clear that it won't be invoked via physical means like App Clip Codes, QR codes, or NFC tags. Double-Check App Clip Configuration in Xcode: Ensure that you haven't accidentally included any unnecessary assets or resources in the App Clip target. Check the build settings, especially any Copy Bundle Resources phases, to ensure that you are only including assets and resources that are essential for the App Clip's functionality. Review Apple's Documentation: Go through Apple's official documentation on creating App Clips in Xcode to make sure you are following best practices and guidelines: Creating an App Clip with Xcode. Test on Device: Before submitting to TestFlight, test your App Clip on a physical device to ensure that it functions as expected and that it's correctly sized. Contact Apple Support: If you've followed all the steps above and are still encountering issues, consider reaching out to Apple Developer Support or using the Apple Developer Forums for further assistance. They may be able to provide specific guidance based on your app's details. It's essential to ensure that your App Clip is well-optimized, follows Apple's guidelines, and is configured correctly in Xcode to meet the size requirements for digital invocations on iOS 16.4 and later.
Oct ’23
Reply to Operation not permitted - MacOS - Swift - UITests
The error you're encountering when trying to create a simple HTTP server in your macOS UI tests target, specifically "result == -1 (Operation not permitted)," is likely due to macOS sandboxing and permissions restrictions. Unlike the main app target, UI tests in macOS have a more restricted environment, which can affect your ability to perform certain operations, such as creating sockets and binding to ports. To create a server socket and bind to a port in a UI tests target, you may need to modify your app's entitlements and ensure that your app has the necessary permissions. Here are some steps to consider: Add Network Entitlements: Make sure that your UI tests target also has the necessary network entitlements. You can add these entitlements to your UI tests target by including an entitlements file specifically for the UI tests target. Create a new entitlements file (e.g., "UITestEntitlements.plist") that contains the network entitlements you provided in your question: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>com.apple.security.app-sandbox</key> <true/> <key>com.apple.security.network.client</key> <true/> <key>com.apple.security.network.server</key> <true/> </dict> </plist> Then, in your UI tests target's build settings, specify this entitlements file as the "Code Signing Entitlements" for the UI tests target. Use a Non-Reserved Port: macOS may have restrictions on binding to well-known ports (e.g., port 80). Try binding to a non-reserved port (e.g., a port number greater than 1024) to see if that resolves the issue. Handle Permissions Prompt: When your server code runs in your UI tests, it may trigger a permissions prompt for network access. Ensure that your UI tests are designed to handle any permissions prompts that may appear during execution. Check for UI Test Constraints: UI tests may run in a separate environment with different constraints compared to the main app target. Make sure that your server code is adapted to run within the context of UI tests. Consider any specific needs or configurations required for UI testing. Use Mocking: Instead of creating an actual server socket in your UI tests, you might consider using mock server responses or stubs for UI testing purposes. This can help avoid network-related issues in UI tests. Check for Code Signing: Ensure that your UI tests target is correctly signed with the appropriate provisioning profile. Check System Preferences: On macOS, you can check the "Security & Privacy" settings in the System Preferences to make sure your app and UI tests have the necessary permissions for network access. By following these steps, you can improve the chances of creating a simple HTTP server within your UI tests target on macOS without encountering "Operation not permitted" errors.
Oct ’23