Foundation

RSS for tag

Access essential data types, collections, and operating-system services to define the base layer of functionality for your app using Foundation.

Posts under Foundation tag

200 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

AttributedString (without NS prefix) and Genmoji
My app uses AttributedString for both text formatting and storage using MarkdownDecodableAttributedStringKey. The new API for Genmoji looks very interesting but I don't see an AttributeScope for it. Is it possible to work around this and stick with AttributedString, am I in the wrong room or should I send in an enhancement request via Feedback Assistant? Thanks a lot for your time!
2
0
219
2w
iOS Developer Beta 18
I want to ask about NSDecimalNumber. is it any changes for use this function ? i test use number like this. example: a = "1000000.0" var a i make number formatter use NumberFormatter b = NSDecimalNumber(string: a with number formatter).decimalValue i try to print b. the value return 1. Anyone can help ?
6
0
239
1w
IOS 18.0 Beta - „Hidden“ Feature ‚Bug‘
Hi, I’ve identified an issue with the “hidden” feature that was added to IOS 18.0. The issue causes the stuff you would like to hide, to become not so hidden anymore. This due to the fact that the apps you are trying to hide are still visible in other parts of the phone. Examples are: Battery consumption location services (and A number of other features in privacy & securit) -Siri -> Apps. I kindly ask the development team to go through the actual feature and identify the possible locations the apps you try to huse could be visible. thanks jorn
2
0
255
3w
Cordova based app not working after updating iOS to 17.5.1
After updating iOS, my Cordova app behaves incorrectly after receiving a voip push. When a push notification is received, my application launches CallKit, displays the Native Dialer screen and starts other necessary services. Until 17.5.1 (possibly 17.5) everything worked correctly. All services and sockets were established/ connected and working. After updating iOS to 17.5, the application crashes, and while voice connection is established the app is no longer active. Xcode logs have these error messages: Invalidating grant <invalid NS/CF object> failed Type: Error | Timestamp: 2024-06-20 13:27:44.719601+02:00 | Process: MyApp | Library: WebKit | Subsystem: com.apple.WebKit | Category: ProcessCapabilities | TID: 0x3a4929 Invalidating grant <invalid NS/CF object> failed Type: Error | Timestamp: 2024-06-20 13:27:44.732219+02:00 | Process: MyApp | Library: WebKit | Subsystem: com.apple.WebKit | Category: ProcessCapabilities | TID: 0x3a4929 Invalidating grant <invalid NS/CF object> failed Type: Error | Timestamp: 2024-06-20 13:27:44.733996+02:00 | Process: MyApp | Library: WebKit | Subsystem: com.apple.WebKit | Category: ProcessCapabilities | TID: 0x3a4929 I am using: Cordova iOS: 6.2 iOS 17.5.1 Can anyone please help?
3
1
952
3w
Document Access Codes and Settings
Currently, there must be a request for access to documents with xcode, but we do not request access. Added NSDocumentDirectoryUsageDescription to info. import SwiftUI import AVFoundation import UniformTypeIdentifiers struct ContentView: View { @State private var audioPlayer: AVAudioPlayer? @State private var isPlaying = false @State private var currentFileName: String = "No file selected" @State private var showingDocumentPicker = false @State private var songList: [String] = UserDefaults.standard.stringArray(forKey: "SavedSongs") ?? [] @State private var currentSongIndex: Int = 0 var body: some View { VStack { Text(currentFileName) .font(.headline) .padding() List { ForEach(songList, id: \.self) { song in HStack { Text(song) .onTapGesture { loadAndPlaySong(named: song) } Spacer() Button(action: { removeSong(named: song) }) { Image(systemName: "trash") .foregroundColor(.red) } } } } .listStyle(PlainListStyle()) HStack(spacing: 10) { Button(action: { showingDocumentPicker = true }) { Text("Load") .font(.system(size: 12)) .frame(width: 50, height: 25) .background(Color.blue) .foregroundColor(.white) .cornerRadius(5) } .padding(.bottom, 20) } .padding() .sheet(isPresented: $showingDocumentPicker) { DocumentPicker(audioPlayer: $audioPlayer, currentFileName: $currentFileName, songList: $songList) } .onAppear { if !songList.isEmpty { loadAndPlaySong(named: songList[currentSongIndex]) } } } func playSong() { audioPlayer?.play() isPlaying = true } func pauseSong() { audioPlayer?.pause() isPlaying = false } func stopSong() { audioPlayer?.stop() audioPlayer?.currentTime = 0 isPlaying = false } func nextSong() { currentSongIndex = (currentSongIndex + 1) % songList.count loadAndPlaySong(named: songList[currentSongIndex]) } func previousSong() { currentSongIndex = (currentSongIndex - 1 + songList.count) % songList.count loadAndPlaySong(named: songList[currentSongIndex]) } func loadAndPlaySong(named songName: String) { guard let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else { return } let fileURL = documentsURL.appendingPathComponent(songName) do { audioPlayer = try AVAudioPlayer(contentsOf: fileURL) audioPlayer?.prepareToPlay() currentFileName = songName playSong() } catch { print("Error loading file: \(error.localizedDescription)") } } func removeSong(named songName: String) { songList.removeAll { $0 == songName } UserDefaults.standard.set(songList, forKey: "SavedSongs") } } struct DocumentPicker: UIViewControllerRepresentable { @Binding var audioPlayer: AVAudioPlayer? @Binding var currentFileName: String @Binding var songList: [String] func makeCoordinator() -> Coordinator { return Coordinator(self) } func makeUIViewController(context: Context) -> UIDocumentPickerViewController { let documentPicker = UIDocumentPickerViewController(forOpeningContentTypes: [UTType.audio]) documentPicker.delegate = context.coordinator return documentPicker } func updateUIViewController(_ uiViewController: UIDocumentPickerViewController, context: Context) {} class Coordinator: NSObject, UIDocumentPickerDelegate { let parent: DocumentPicker init(_ parent: DocumentPicker) { self.parent = parent } func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) { guard let url = urls.first else { return } do { if url.startAccessingSecurityScopedResource() { defer { url.stopAccessingSecurityScopedResource() } let fileName = url.lastPathComponent let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! let destinationURL = documentsURL.appendingPathComponent(fileName) if FileManager.default.fileExists(atPath: destinationURL.path) { try FileManager.default.removeItem(at: destinationURL) } try FileManager.default.copyItem(at: url, to: destinationURL) parent.audioPlayer = try AVAudioPlayer(contentsOf: destinationURL) parent.audioPlayer?.prepareToPlay() parent.currentFileName = fileName if !parent.songList.contains(fileName) { parent.songList.append(fileName) UserDefaults.standard.set(parent.songList, forKey: "SavedSongs") } } else { print("I can't get file access.") } } catch { print("An error occurred while loading the file: \(error.localizedDescription)") } } func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) { } } }
0
0
171
3w
Issue with Background Serial Communication Using Type-C on iPad Pro
Hello, I am experiencing an issue with background serial communication on my iPad Pro when using a Type-C connection to an external device. Specifically, when the app is inactive, in low power mode, or when the screen is locked (i.e., not active), the communication with the external device is interrupted. However, this problem does not occur when using a Lightning cable on my iPad Mini. In that setup, the background serial communication works seamlessly under the same conditions. Has anyone encountered a similar issue or have any insights into why the behavior differs between Type-C and Lightning connections? Any suggestions or workarounds would be greatly appreciated. Thank you!
1
0
201
3w
Permission denied: GenerativeFunctionMetrics
A sample of some error messages that are presented in the Xcode log for executon of a program. There is nothing in the messages that will help identify a component as the origin of the message, nor is there a locatable derinition for the various labels and fields of the text. What component or even framework does this set of messages originate? Your search engine is useless because it returns gibberish. It doesn’t even follow the common behavior of SEARCH ENGINES because it takes label strings compounded from common words and searches for the common word instead of using the catenated string that is the internal variable name that is in the text. 2024-06-22 19:45:58.089943-0500 RoomPlanExampleApp[733:30145] [ClientDonation] (+[PPSClientDonation isRegisteredSubsystem:category:]) Permission denied: GenerativeFunctionMetrics / ANEInferenceOperationPrepareForEncode. I am looking for a definition of the error with a way to locate the context in which the error occurs. 2024-06-22 19:45:58.089967-0500 RoomPlanExampleApp[733:30145] [ClientDonation] (+[PPSClientDonation sendEventWithIdentifier:payload:]) Invalid inputs: payload={ aneModelPath = "/System/Library/PrivateFrameworks/RoomScanCore.framework/PrecompiledModels/lcnn_floorplan_model.bundle/H14G.bundle/main/segment_0__ane/net.hwx"; bundleIdentfier = "com.example.apple-samplecode.RoomPlanExampleApp9QSS565686"; } 2024-06-22 19:45:58.094770-0500 RoomPlanExampleApp[733:30145] [ClientDonation] (+[PPSClientDonation sendEventWithIdentifier:payload:]) Invalid inputs: payload={ bundleIdentfier = "com.example.apple-samplecode.RoomPlanExampleApp9QSS565686"; e5FunctionName = main; numSegments = 1; }
1
0
264
3w
iOS 17.4.1 Crash with WebCore "cache_remove_all"
Our iOS 17.4.1 users are experiencing a crash when we try to convert Markdowns to HTML. We're wondering what could be the trigger for this crash 💥. we would love to get some help. Here is the full stack: Crashed: WebThread 0 WebCore 0x2ee8 <redacted> + 20 1 WebCore 0x15df7d0 <redacted> + 11068 2 WebCore 0x191b6b0 <redacted> + 264 3 WebCore 0x15e0e7c <redacted> + 784 4 WebCore 0x1e1a01c WebCore::LocalFrame::~LocalFrame() + 548 5 WebCore 0x1e1a760 WebCore::LocalFrame::~LocalFrame() + 16 6 WebCore 0x1e5470c WebCore::Page::~Page() + 7264 7 WebKitLegacy 0xb65e8 __29-[WebView(WebPrivate) _close]_block_invoke + 372 8 WebCore 0x214d070 <redacted> + 648 9 CoreFoundation 0x3762c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28 10 CoreFoundation 0x368a8 __CFRunLoopDoSource0 + 176 11 CoreFoundation 0x350b8 __CFRunLoopDoSources0 + 340 12 CoreFoundation 0x33d88 __CFRunLoopRun + 828 13 CoreFoundation 0x33968 CFRunLoopRunSpecific + 608 14 WebCore 0xe90110 <redacted> + 780 15 libsystem_pthread.dylib 0x2a90 _pthread_start + 136 16 libsystem_pthread.dylib 0x1fcc thread_start + 8 com.apple.uikit.datasource.diffing 0 libsystem_kernel.dylib 0x249c __psynch_cvwait + 8 1 libsystem_pthread.dylib 0x1590 _pthread_cond_wait + 1228 2 JavaScriptCore 0x7d5f8 ***::ThreadCondition::timedWait(***::Mutex&, ***::WallTime) + 160 3 JavaScriptCore 0x51d78 ***::ParkingLot::parkConditionallyImpl(void const*, ***::ScopedLambda<bool ()> const&, ***::ScopedLambda<void ()> const&, ***::TimeWithDynamicClockType const&) + 2072 4 JavaScriptCore 0x42468 ***::LockAlgorithm<unsigned char, (unsigned char)1, (unsigned char)2, ***::EmptyLockHooks<unsigned char> >::lockSlow(***::Atomic<unsigned char>&) + 216 5 WebCore 0xe8da54 <redacted> + 280 6 WebCore 0xe8ea38 WebThreadLock + 132 7 UIFoundation 0xdb68c -[NSHTMLReader _loadUsingWebKit] + 1448 8 UIFoundation 0xdc234 -[NSHTMLReader attributedString] + 24 9 UIFoundation 0x83c88 _NSReadAttributedStringFromURLOrDataCommon + 6440 10 UIFoundation 0x7ed34 _NSReadAttributedStringFromURLOrData + 288 11 UIFoundation 0x7ebac -[NSAttributedString(NSAttributedStringUIFoundationAdditions) initWithData:options:documentAttributes:error:] + 148 ...
1
0
197
Jun ’24
Privacy Solution for Apps in iOS (Please Read)
Hear me out, developers at Apple! You've done an amazing job with privacy so far. The introduction of ContactAccess and the Contact Access Button this year is truly an amazing work of art. Well done. However, all the way back to the first iPhone I got in 2007, I wished Apple would make API's available to access the users installed apps (in a privacy way). This would (further) open up apps in the category of App Managers and App Launchers. Back in the early days the trick was to use deep link, but that was also awkward, since you needed to know the deeplink upfront and the apps needed to support it. Not ideal. It also had a side effect that Apple noticed, that evil party's used it to scan your device to know which apps you had installed and create a profile from that. Apple fixed that by using LSApplicationQueriesSchemes. Now you have to tell the App upfront which apps you will be calling (up to 50), or use Universal Link to be freed from this limitation again. Again not ideal. Why not turn it around and let the user decide? User central. Imagine an App Launcher app. There is a button in the launcher app where you as a user can click on to add an app. It calls an api available from Apple to launch a privacy shielded sheet with the apps the user got installed on its device. These are not exposed to the launcher app. When the user clicks on the installed app (or apps) it likes to add, the launcher app will get identifiers to launch the app. That's it. This would be limited access, perhaps the api could also expose full access, so permission could be granted once and the app will get all identifiers available. The choice will be up to the user. One step further, but this would be more nice-to-have, is the ability to access meta data of the app, such as icon, title, last launched, app size, etc. This way App Launchers can make decisions such as putting the most recent launched app in front or App Managers can use this to decide which apps you are not using and can advise to remove them to clean up space. Love to hear everyone's opinion. So let it be the start of the discussion.
3
0
315
Jun ’24
NSURL CFNetwork Crashed in iOS18 Beta
When I initiate the following request in the app delegate, it is good in iOS 17, but it will crash in iOS 18. The code is as below: NSString *url = @"https://www.baidu.com"; NSString * restr = [NSString stringWithContentsOfURL:[NSURL URLWithString:url] encoding:NSUTF8StringEncoding error:nil]; The stack is as below: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSFileManager createDirectoryAtURL:withIntermediateDirectories:attributes:error:]: URL is nil' *** First throw call stack: ( 0 CoreFoundation 0x00007ff8004c14d5 __exceptionPreprocess + 242 1 libobjc.A.dylib 0x00007ff800084116 objc_exception_throw + 62 2 Foundation 0x00007ff800f00861 -[NSFileManager contentsOfDirectoryAtPath:error:] + 0 3 CFNetwork 0x00007ff804c66bfd -[_NSHTTPAlternativeServicesStorage _onqueue_initializeDatabaseIfNotEmpty:] + 488 4 CFNetwork 0x00007ff804c69350 __66-[_NSHTTPAlternativeServicesStorage HTTPServiceEntriesWithFilter:]_block_invoke + 48 5 libdispatch.dylib 0x0000000115349f32 _dispatch_client_callout + 8 6 libdispatch.dylib 0x000000011535ad86 _dispatch_lane_barrier_sync_invoke_and_complete + 133 7 CFNetwork 0x00007ff804c65bf7 -[_NSHTTPAlternativeServicesStorage HTTPServiceEntriesWithFilter:] + 211 8 CFNetwork 0x00007ff804cd5ccc _ZN11TubeManager34_onqueue_enqueueRequestForProtocolEP25MetaConnectionCacheClientPK18HTTPRequestMessage21MetaConnectionOptionsP16BaseAwaitingTube + 264 9 CFNetwork 0x00007ff804bf8b0c ___ZN12XTubeManager25enqueueRequestForProtocolEP25MetaConnectionCacheClientPK18HTTPRequestMessage21MetaConnectionOptionsPK17CoreSchedulingSet_block_invoke + 328 10 CFNetwork 0x00007ff804bf8832 _ZN12XTubeManager15withTubeManagerEPK17CoreSchedulingSetU13block_pointerFvP15GlueTubeManagerE + 516 11 CFNetwork 0x00007ff804d27823 _ZN12HTTPProtocol81asynchronouslyCreateAndOpenStream_WithMessage_AfterCookiesAndAuthenticatorHeadersEP15__CFHTTPMessage + 6077 12 CFNetwork 0x00007ff804d25ea3 _ZN12HTTPProtocol48asynchronouslyAddAuthenticatorHeadersAndContinueEP15__CFHTTPMessage + 103 13 CFNetwork 0x00007ff804d295b3 ___ZN12HTTPProtocol35asynchronouslyAddCookiesAndContinueEP15__CFHTTPMessage_block_invoke_3 + 26 14 CFNetwork 0x00007ff804e0fdb7 ___ZNK18QCoreSchedulingSet12performAsyncEU13block_pointerFvvE_block_invoke + 41 15 libclang_rt.asan_iossim_dynamic.dyl 0x0000000115d0fa4c __wrap_dispatch_async_block_invoke + 204 16 libdispatch.dylib 0x0000000115348ba9 _dispatch_call_block_and_release + 12 17 libdispatch.dylib 0x0000000115349f32 _dispatch_client_callout + 8 18 libdispatch.dylib 0x0000000115351e3b _dispatch_lane_serial_drain + 1078 19 libdispatch.dylib 0x0000000115352bbc _dispatch_lane_invoke + 448 20 libdispatch.dylib 0x0000000115353be7 _dispatch_workloop_invoke + 876 21 libdispatch.dylib 0x000000011535fcc6 _dispatch_root_queue_drain_deferred_wlh + 318 22 libdispatch.dylib 0x000000011535f205 _dispatch_workloop_worker_thread + 853 23 libsystem_pthread.dylib 0x000000011521db84 _pthread_wqthread + 327 24 libsystem_pthread.dylib 0x000000011521cacf start_wqthread + 15 ) libc++abi: terminating due to uncaught exception of type NSException
2
0
225
Jun ’24
Sendability for Stream, InputStream, etc.
I have a project with some legacy networking code that uses the Stream (formerly NSStream) family of classes, including Stream, InputStream, OutputStream, and StreamDelegate. None of these are sendable, so I get a lot of warnings when implementing delegate methods in a @MainActor class. These classes seem like they could be sendable. Is this something that will happen soon? Is it a bug I should report? The networking code that uses these classes runs great, and hasn't needed changes for years, so my current solution is to just mark these unchecked: extension Stream: @unchecked Sendable { } extension InputStream: @unchecked Sendable { } extension OutputStream: @unchecked Sendable { } This makes the compiler happy, but makes me feel kind of bad. Is there something else I could do?
1
0
213
Jun ’24
Error when downloading files with multiple background urlsession
Hi, I am trying to download multiple files in background (using multiple background urlsession). I initiate the download on click of a button and push the app to background where the download should happen. I am getting the following error: Error Domain=NSCocoaErrorDomain Code=4 "“CFNetworkDownload_EYp3BT.tmp” couldn’t be moved to “Documents” because either the former doesn’t exist, or the folder containing the latter doesn’t exist." UserInfo={NSSourceFilePathErrorKey=/private/var/mobile/Containers/Data/Application/85AEEB4F-1512-4C0C-8B04-C9C73634CC49/Library/Caches/com.apple.nsurlsessiond/Downloads/com.mycompany.DownloadMultipleFilesTestApp/CFNetworkDownload_EYp3BT.tmp, NSUserStringVariant=(\n Move\n), NSDestinationFilePath=/var/mobile/Containers/Data/Application/85AEEB4F-1512-4C0C-8B04-C9C73634CC49/Documents/file-441966.pdf, NSFilePath=/private/var/mobile/Containers/Data/Application/85AEEB4F-1512-4C0C-8B04-C9C73634CC49/Library/Caches/com.apple.nsurlsessiond/Downloads/com.mycompany.DownloadMultipleFilesTestApp/CFNetworkDownload_EYp3BT.tmp, NSUnderlyingError=0x28155f900 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}} In my sample code attached here i am trying with 500 background urlsession (one download task per each url session) I have implemented the required methods: application(_:handleEventsForBackgroundURLSession:completionHandler) and urlSessionDidFinishEvents forBackgroundURLSession:) I have found that the error happens because of two callbacks to urlSession(_:downloadTask:didFinishDownloadingTo:) where i move the file from temporary location to a location in my app's documents directory. The first time the file is present at the location, but for the second callback (with same urlsession id, task id and location values) to urlSession(_:downloadTask:didFinishDownloadingTo:) the file isnt present there and so the move fails. Can someone please explain this erratic behaviour ? Is this a known issue with URLSession ? For a repro, you can use the code attached above, test on a physical device without running app from xcode ie launch the app from phone's home screen, click on the download button and send the app to background. Check logs in the console app on mac Test environment: iPhone 8plus with iOS 16.7.8
3
9
368
Jun ’24
JSON Encoder Crashing
Hi For some of the user the JSON Encoder is giving crash while converting array of Models into the dictionary its not reproducible at our end. Below is the stack trace of the issue 2024-06-14_21-18-38.4054_-0500-90aad9908d4fb2c7b8e49ce4b3025fab79674e31.crash Please help with above crash how can we reproduce and what should be the solution for this. Thanks
1
0
212
Jun ’24