Swift is a powerful and intuitive programming language for Apple platforms and beyond.

Posts under Swift tag

200 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

NSApplicationDelegate open URLs only called after second drop
I want to make a simple droplet application. I've set the document types to include com.adobe.pdf files, and I am now receiving callbacks to the app delegate's application(_:open:) callback when I drop PDFs on the app icon… But not the first time. It doesn't matter how long I wait, or whether the app is already open—the first drop never triggers the callback. All subequent drops work as expected, and I get URLs to all the files dropped. What might be wrong? How can I debug this?
1
0
282
Oct ’24
Warning in Xcode console: Couldn't read values in CFPrefsPlistSource
I have enabled an App Group in my App and the Widget Extension. I use it to share my UserDefaults. Every time the app starts I now get the following error message in the Xcode console: Couldn't read values in CFPrefsPlistSource<0x303034510> (Domain: group.XX.XXXX.XXXX, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null), Contents Need Refresh: Yes): Using kCFPreferencesAnyUser with a container is only allowed for System Containers, detaching from cfprefsd The shared UserDefaults itself works without problems. Any ideas how I could get rid of this warning?
1
0
485
Oct ’24
Swift xcframeworks built with Xcode 16 not works in Xcode 15 projects
Hello, when I use xcode 16 build swift xcframeworks and provide it for my customer, however they can not use it their xcode 15 projects. Undefined symbol: _swift_FORCE_LOAD$_swift_Builtin_float Undefined symbol: _+ _swift_FORCE_LOAD$_swift_errno Undefined symbol: _+ _swift_FORCE_LOAD$_swift_math Undefined symbol: _+ _swift_FORCE_LOAD$_swift_signal Undefined symbol: _+ _swift_FORCE_LOAD$_swift_stdio Undefined symbol: _+ _swift_FORCE_LOAD$_swift_time Undefined symbol: _+ _swift_FORCE_LOAD$_swiftsys_time Undefined symbol: _+ _swift_FORCE_LOAD$_swiftunistd What should I do? And macOS Sequoia does not support Xcode 15.4. I can not build my frameworks with Xcode 15.4 now.
1
2
220
Oct ’24
Unexpected behavior when iPad is unlock and the application goes to Foreground. something happens and the application goes to background and foreground in a small period of time.
I have the our device connected , with Assistive Touch enabled and the application running in the foreground. At this point, I place the screen on standby and leave the device unattended for 10 minutes. After this period, I return, unlock the screen, and observe that our app is still running, and the connection with the device is re-initiated. However, something occurs at this stage that causes the application to briefly switch to the background and then immediately return to the foreground. This behavior leads to system instability. Ideally, once the application is running in the foreground, it should not transition to the background automatically. However, it seems to be doing so for a short duration—momentarily switching from the foreground to the background, then back to the foreground—which is causing the observed instability. OK, the iPad screen is unlocked AND App Appears. 2024-10-01 13:15:55 LOG: APP > Scene did become active 2024-10-01 13:15:55 LOG: APP > Init device Suddenly the application goes to background by itself?!?!?! 2024-10-01 13:15:55 LOG: APP > Scene will change from Foreground to Background 2024-10-01 13:15:55 LOG: APP > Scene changed to Background 2024-10-01 13:15:56 LOG: APP > Scene Will Enter to Foreground 2024-10-01 13:15:56 LOG: APP > Nib Name previous load : Home Other example OK, the iPad screen is unlocked AND App Appears. 2024-10-01 11:23:55 LOG: APP > Scene Will Enter to Foreground 2024-10-01 11:23:56 LOG: APP > Scene did become active 2024-10-01 11:23:56 LOG: APP > Init connection Suddenly the application goes to background by itself?!?!?! 2024-10-01 11:23:56 LOG: APP > Scene will change from Foreground to Background 2024-10-01 11:23:56 LOG: APP > Scene changed to Background 2024-10-01 11:23:56 LOG: APP > Scene Will Enter to Foreground 2024-10-01 11:23:56 LOG: APP > Scene did become active 2024-10-01 11:23:56 LOG: APP > Scene will change from Foreground to Background 2024-10-01 11:23:56 LOG: APP > Scene changed to Background 2024-10-01 11:23:56 LOG: APP > Scene Will Enter to Foreground 2024-10-01 11:23:56 LOG: APP > Nib Name previous load : Home FA FB15345245 this is happening under iPadOS18.1 beta5 and iPad12.9" 6th gen. Would you mind taking a look at this issue ?
2
0
333
Oct ’24
Issues with Apple Nearby Interaction app not detecting DWM3001CDK accessory
Hi everyone, I’m having trouble getting my iPhone 11 to detect a DWM3001CDK as an accessory using the Apple Nearby Interaction app. Here’s the background: Two years ago, I successfully tested UWB ranging between the same devices (iPhone 11 and DWM3001CDK, which is based on the Qorvo DW3110 IC and an nRF52833 SoC with Bluetooth 5.2). At that time, the Nearby Interaction app was in beta and worked well for my tests. Now, with the stable version of the app, I’m encountering an issue. Here’s what I’ve done so far: I erased the DWM3001C and flashed it with the Qorvo Nearby Interaction firmware (v3.2.0, "DWM3001CDK-QANI-FreeRTOS_full_QNI_3_0_0.hex") using J-Flash Lite V7.86g on Windows. With this configuration, I can connect the iPhone 11 to the accessory using the Qorvo NI apps, both in the foreground and background. However, when I compile and run the project "ImplementingSpatialInteractionsWithThirdPartyAccessories" (available on the Apple Developer website) on my iPhone 11 (running iOS 17.7), the app remains stuck on the "Scanning for accessory" screen and doesn’t find the device, even though I’ve given the app permission to use Bluetooth. Could this be due to an issue with the firmware I flashed on the DWM3001CDK, or might there be something else causing the problem? Any help or insights would be appreciated! Thanks in advance.
0
0
194
Oct ’24
NEHotspotConfigurationManager apply method error always return Success
I'm trying to handle the error in NEHotspotConfigurationManager connection method.When i try even OS network connect dialog showing with "Cannot connect" response return as "Success". In my flow i'm trying to connect to a private network. First i connect using below code and then set the IP Address,SubNetMask,Router and DNS server address manually to already added Wifi by running below code. I'm doing this manually because as i understand you cannot set the IP Address,SubNetMask,Router and DNS server address using Swift. https://forums.developer.apple.com/forums/thread/96834?page=2 I read the above thread and what i can understand from that is it's a bug in the os method. So does this problem fixed on latest iOS version? or is there a way to handle this problem? Error handler code→ let eapSetting = NEHotspotEAPSettings() eapSetting.username = self.username eapSetting.password = self.password eapSetting.supportedEAPTypes = [NEHotspotEAPSettings.EAPType.EAPPEAP.rawValue as NSNumber] eapSetting.trustedServerNames = ["ABC"] NEHotspotConfigurationManager.shared.removeConfiguration(forSSID: self.ssid) let hotspotConfiguration = NEHotspotConfiguration(ssid: self.ssid, eapSettings: eapSetting) manager.apply(hotspotConfiguration){ (error) in if let error = error { print("Error") return } else { print("Success") return } }
5
0
309
Oct ’24
Interpreting received "Data" object in cpp
Hello Everyone, I have a use case where I wanted to interpret the "Data" object received as a part of my NWConnection's recv call. I have my interpretation logic in cpp so in swift I extract the pointer to the raw bytes from Data and pass it to cpp as a UnsafeMutableRawPointer. In cpp it is received as a void * where I typecast it to char * to read data byte by byte before framing a response. I am able to get the pointer of the bytes by using // Swift Code // pContent is the received Data if let content = pContent, !content.isEmpty { bytes = content.withUnsafeBytes { rawBufferPointer in guard let buffer = rawBufferPointer.baseAddress else { // return with null data. } // invoke cpp method to interpret data and trigger response. } // Cpp Code void InterpretResponse (void * pDataPointer, int pDataLength) { char * data = (char *) pDataPointer; for (int iterator = 0; iterator < pDataLength; ++iterator ) { std::cout << data<< std::endl; data++; } } When I pass this buffer to cpp, I am unable to interpret it properly. Can someone help me out here? Thanks :) Harshal
3
0
568
Oct ’24
Unable to obtain APNS token in xCode Swift after iOS 18 Upgrade
After upgrading to iOS 18, in my app development using xCode 16.0 (16A242d) and Swift, I am totally unable to obtain an APNS token from my own device using didRegisterForRemoteNotificationsWithDeviceToken The delegate simply won’t fire. I was able to do so repeatedly in the same app a week earlier, using iOS 17xx. That part of the code has not changed. I just now restored my phone and installed a clean version of iOS 18, but the issue has not changed. Have tried using WiFi and also cellular networks. It is a no-go.
4
0
314
Oct ’24
Possible NavigationSplitView bug
With macOS 15, I'm noticing a new behavior when initializing a NavigationSplitView with columnVisibility. For example: @State var sidebar = NavigationSplitViewVisibility.all var body: some View { ZStack { NavigationSplitView(columnVisibility: $sidebar) { This code previous to macOS 15 would behave as expected: the sidebar could be toggled and the views would stay intact. However, when you update sidebar after updating to macOS 15, the entire view is reinitialized, meaning that every single child view that depends on this parent view is also reinitialized. Is this expected behavior? Simply clicking the toggle sidebar UI button does not reinitialize views, but when you initialize a NavigationSplitView with the column visibility, changes to the sidebar will completely reload the UI. Has anyone else experienced this?
0
0
153
Sep ’24
Returned from Unity games causes my app to slow and it works normal after siri or locking unlocking phone
Dear Developers, Am facing this issue on my production app. Tried everything. Removed almost everything and tested the app. Even then this issue happens. The unity games, am talking about are the slow and sluggish types, which feel like 30 fps and after returning from them, my app sounds slow and feels a little bit sluggish. As soon as i lock/unlock the device , it becomes perfectly fine. Even i was debugging with xcode, i had the issue, then i rebuild the app in xcode and opening it on device, the same issue. As soon as i locked the device or opened siri with lockbutton or moved to a native app, and came back, app is completely fine. Craziest issue, i have ever seen. Though killing the app and opening it again on iphone also works. Only anxiety is that maybe my users when returning from other slow 3rd party games which are my competitors might slow down the experience. I have tried almost everything in my app, removed all functions and just ran sounds. Retried with different ways of playing sounds. Nothing works. Dont know it is a frame rate issue, because i replaced all my animations causing framerate not to cross 60fps even then didnt work. Device on which am testing is Iphone 14 pro max.
0
0
201
Sep ’24
AppleArchive crashes on corrupt archive instead of failing gracefully
We're trying to implement a backup/restore data feature in our business productivity iPad app using UIDocumentPickerViewController and AppleArchive, but discovered AppleArchive crashes instead of failing gracefully when decrypting a corrupt archive. As described in forum post 765101, UIDocumentPickerViewController can handoff a corrupt copy of an archive to UIDocumentPickerDelegate under specific circumstances. We've duplicated this behavior with iPadOS 16.6.1 and 17.7 when building our app with Xcode 15.4 targeting minimum deployment of iPadOS 16. We haven't tested this with the bleeding edge iPadOS 18. Our app is primarily Objective-C, but it utilizes the Swift-based AppleArchive 'EncryptingAndDecryptingDirectories' sample code associated with WWDC21 session: 10233: Bring Encrypted Archives and Performance Improvements to Your App with Accelerate. The WWDC21 'EncryptingAndDecryptingDirectories' Swift sample project crashes in a similar manner when a corrupt archive file created by UIDocumentPickerViewController is dropped into the sample app's window for decryption (see attached crash log). Does anyone know if there's a workaround for the 'EncryptingAndDecryptingDirectories' sample project to prevent AppleArchive from crashing when decrypting a corrupt archive? crash log.txt
2
0
262
Sep ’24
iOS 18 Issue: When we add arm64 into Excluded Architecture and try to present screen, Screen will get froze and unable to select images.
I am using Storyboard to present a UIImagePickerController on a view controller (a simple initial view without any navigation or tab bar). Due to a requirement, we need to exclude the arm64 architecture. However, when I try to present the screen, it gets stuck. I am unable to select an image, and the screen becomes inaccessible. It's happening only on simulator. Does anyone have any solution.
1
0
310
Oct ’24
XCode or IOS 18 Bug?
I just finished updating my app to support the new screen sizes for the iPhone 16 series devices (iPhone16 Pro and iPhone 16 Pro Max). In testing the changes, I've come across what I hope is simply a bug in the Xcode 16 simulators. I don't have any actual devices (yet) that I can use to test. In landscape mode, my app presents a "tab" on the right side of the screen that can be tapped to bring out another view. Activating the tab is based on capturing the screen coordinates from a "tap". In Xcode 16, using the iPhone16 simulators on IOS 18, the area of the tab does not recognize that a tap has occurred. After hours of banging my head against my laptop, it dawned on me that the area of the screen that hosts the "tab" is in exactly the same location as "unavailable area" that represents the camera on the simulator. I have arrived at the assumption that the issue is that the simulator is treating the same space at the bottom of the device as it treats that reserved area at the top of the screen. Has anyone else experienced this? Is this a bug in the simulator or is this expected behavior on the iPhone 16 series devices?
3
1
712
Sep ’24
Issue with OCR on Swift iOS App: Roboflow API Bounding Boxes Missing After Response
Hi everyone, I'm working on an iOS app built in Swift using Xcode, where I'm integrating Roboflow's object detection API to extract items from grocery receipts. My goal is to identify key information (like items, total, tax, etc.) from the images of these receipts. I'm successfully sending images to the Roboflow API and receiving predictions with bounding box data, but when I attempt to extract text from the detected regions (bounding boxes), it appears that the text extraction is failing—no text is being recognized. The issue seems to be that the bounding boxes are either not properly being handled or something is going wrong in the way I process the API response. Here's a brief breakdown of what I'm doing: The image is captured, converted to base64, and sent to the Roboflow API. The API response comes back with bounding boxes for the detected elements (items, date, subtotal, etc.). The problem occurs when I try to extract the text from the image using the bounding box data—it seems like the bounding boxes are being found, but no text is returned. I suspect the issue might be happening because the app’s segue to the results view controller is triggered before the OCR extraction completes, or there might be a problem in my code handling the bounding box response. Response Data: { "inference_id": "77134cce-91b5-4600-a59b-fab74350ca06", "time": 0.09240847699993537, "image": { "width": 370, "height": 502 }, "predictions": [ { "x": 163.5, "y": 250.5, "width": 313.0, "height": 127.0, "confidence": 0.9357666373252869, "class": "Item", "class_id": 1, "detection_id": "753341d5-07b6-42a1-8926-ecbc61128243" }, { "x": 52.5, "y": 417.5, "width": 89.0, "height": 23.0, "confidence": 0.8819760680198669, "class": "Date", "class_id": 0, "detection_id": "b4681149-d538-47b1-8700-d9528bf1daa0" }, ... ] } And the log showing bounding boxes: Prediction: ["width": 313, "y": 250.5, "x": 163.5, "detection_id": 753341d5-07b6-42a1-8926-ecbc61128243, "class": Item, "height": 127, "confidence": 0.9357666373252869, "class_id": 1] No bounding box found in prediction. I've double-checked the bounding box coordinates, and everything seems fine. Does anyone have experience with using OCR alongside object detection APIs in Swift? Any help on how to ensure the bounding boxes are properly processed and used for OCR would be greatly appreciated! Also, would it help to delay the segue to the results view controller until OCR is complete? Thank you!
0
0
333
Sep ’24
Non-XCode crash logging for iOS?
I test my app, by building it and hoping it will go on my iOS. This is the only workflow I have to test my testing app. I use AVAudioEngine and AVAudioSession. It sounds painful but, yes. I literally comment out parts and build the app everytime and see if it would crash or not. Sometimes I'd get Crash Logs in the Analytics part, but I haven't managed to get them there anymore. So I had no more Crash Logs. I was wondering if there's a function or something. Maybe something that I can do in AppDelegate to make it create a Crash Log somewhere? Uncaught Exception overwrite, didn't solve the issue for me. It really has to be an actual crash log, something that catches these. If someone knows, let me know! Thanks
1
0
246
Sep ’24
Calling `requestAuthorization(options:completionHandler:)` in Swift 6 leads to `EXC_BAD_INSTRUCTION` crash.
I am in the process of evaluating Swift 6 and I noticed that when using the completion handler version of the requestAuthorization the application crashes with EXC_BAD_INSTRUCTION exception. Using this code: let center = UNUserNotificationCenter.current() center.requestAuthorization(options: [.alert, .sound, .badge]) { success, error in print(success) } Crashes when the project is build with Swift 6 and works normalising when build with Swift 5. The only solution that I have found so far is to switch to using the async version of that API: Task { let center = UNUserNotificationCenter.current() do { if try await center.requestAuthorization(options: [.alert, .sound, .badge]) == true { print("success") } else { print("fail") } } catch { print("Error") } } Is the a known issue? I have submitted feedback with ID "FB15294185".
2
0
310
Oct ’24
Issue with Xcode 16 - Errors When Splitting Code for Widgets
I’m encountering an issue since I started using Xcode 16. I have a widget in my app, and I'm trying to organize the code by splitting it into different files for better structure. However, when I do this, I get an error: error: Unexpected input file: /Users/******/Desktop/TestApp/TestAppWidget/Provider.Swift (in target 'TestAppWidgetExtension' from project 'TestApp') I want to emphasize that if I keep all the code in one file, everything works fine. I've checked the Target Membership, and it's set up correctly. but I don't understand why this is happening only in Xcode 16. Has anyone else experienced a similar issue or has any ideas on why this is occurring? I would appreciate any help!
3
0
356
Sep ’24
error: memory read failed for 0x10
Issues Integrating FaceTec SDK into a Custom iOS Framework Hi Community, I am working on a custom iOS framework that integrates FaceTec SDK for biometric authentication, but I am facing issues with properly running the SDK within my framework. Below is the context and specific issues I need help with: Context: I have created a framework that includes a UIViewController called FinishViewController. This controller is responsible for managing the FaceTec SDK session. Below is a simplified snippet of the code used to initialize and handle FaceTec SDK: import UIKit import FaceTecSDK import LocalAuthentication class FinishViewController: UIViewController, URLSessionDelegate{ var utils: SampleAppUtilities! var latestProcessor: Processor! var latestExternalDatabaseRefID: String = "" var latestSessionResult: FaceTecSessionResult! var latestIDScanResult: FaceTecIDScanResult! @IBOutlet weak var elTelon: UIView! var isRealPerson = false var isNotSuccessful = false var isCancelled = false override func viewDidLoad() { super.viewDidLoad() utils = SampleAppUtilities(vc: self) // Initialize FaceTec SDK Config.initializeFaceTecSDKFromAutogeneratedConfig(completion: { initializationSuccessful in if(initializationSuccessful) { self.onFaceTecSDKInitializationSuccess() } else { self.onFaceTecSDKInitializationFailure() } }) DispatchQueue.main.asyncAfter(deadline: .now() + 2) { [self] in getSessionToken() { sessionToken in _ = LivenessCheckProcessor(sessionToken: sessionToken, fromViewController: self) .lvResponseDelegate = self //self.latestProcessor = AuthenticateProcessor(sessionToken: sessionToken, fromViewController: self) } } // Do any additional setup after loading the view. } func onFaceTecSDKInitializationFailure() { // Displays the FaceTec SDK Status to text field if init failed self.utils.displayStatus(statusString: "\(FaceTec.sdk.description(for: FaceTec.sdk.getStatus()))") } func onFaceTecSDKInitializationSuccess() { // self.utils.enableButtons(shouldEnable: true) // Set your FaceTec Device SDK Customizations. ThemeHelpers.setAppTheme(theme: utils.currentTheme) // Set the sound files that are to be used for Vocal Guidance. // Set the strings to be used for group names, field names, and placeholder texts for the FaceTec ID Scan User OCR Confirmation Screen. SampleAppUtilities.setOCRLocalization() let currentTheme = Config.wasSDKConfiguredWithConfigWizard ? "Config Wizard Theme" : "FaceTec Theme" utils.handleThemeSelection(theme: currentTheme) self.utils.displayStatus(statusString: "Initialized Successfully.") } func onComplete() { if !self.latestProcessor.isSuccess() { // Reset the enrollment identifier. self.latestExternalDatabaseRefID = ""; } } func getSessionToken(sessionTokenCallback: @escaping (String) -> ()) { let endpoint = Config.BaseURL + "/session-token" let request = NSMutableURLRequest(url: NSURL(string: endpoint)! as URL) request.httpMethod = "GET" // Required parameters to interact with the FaceTec Managed Testing API. request.addValue(Config.DeviceKeyIdentifier, forHTTPHeaderField: "X-Device-Key") request.addValue(FaceTec.sdk.createFaceTecAPIUserAgentString(""), forHTTPHeaderField: "User-Agent") request.addValue(FaceTec.sdk.createFaceTecAPIUserAgentString(""), forHTTPHeaderField: "X-User-Agent") let session = URLSession(configuration: URLSessionConfiguration.default, delegate: self, delegateQueue: OperationQueue.main) let task = session.dataTask(with: request as URLRequest, completionHandler: { data, response, error in // Ensure the data object is not nil otherwise callback with empty dictionary. guard let data = data else { print("Exception raised while attempting HTTPS call.") return } if let responseJSONObj = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.allowFragments) as! [String: AnyObject] { if((responseJSONObj["sessionToken"] as? String) != nil) { sessionTokenCallback(responseJSONObj["sessionToken"] as! String) return } else { print("Exception raised while attempting HTTPS call.") } } }) task.resume() } func getLatestExternalDatabaseRefID() -> String { return latestExternalDatabaseRefID; } func setLatestSessionResult(sessionResult: FaceTecSessionResult) { latestSessionResult = sessionResult print("The latestSessionResult is: ", latestSessionResult!) } @IBAction func finish(_ sender: Any) { AppConfig.shared.intentosCaptura = 1 self.performSegue(withIdentifier: "unwindToRoot", sender: self) } } When I try to run the SDK, no initial compilation or runtime errors occur, but the SDK does not start as expected and there are no clear indications or errors in the console to help me diagnose the problem. I have checked the wiring of all the IBOutlet and IBAction, and everything seems to be in order. Are there any special considerations I should be aware of when integrating FaceTec SDK into a framework rather than an application directly? Are there any best practices for managing SDK initialization or view lifecycles within an iOS framework? Has anyone faced similar issues when integrating third-party SDKs into custom frameworks and how did they resolve them?
1
0
298
Sep ’24
App Clip Card not appearing on initial page load
I have no idea why my app clip card is not showing on initial url load, it doesn't even show when I refresh the page. The only thing that works is pull to refresh (once or more times). After that, it shows up. Is it possible to fix this issue and show app clip card on url load? Here's the appclip url (for some reason I can't post href): https://app.celer.life/reading-exercise Initial load: After pull to refresh:
2
0
233
Sep ’24