Posts

Post not yet marked as solved
12 Replies
460 Views
Is there a good explanation somewhere of where background task identifiers are registered and how to modify these? I have entered the "Permitted background task scheduler identifiers" into my xcode target, and it is replicated automatically in Info.plist. I can run the app (which registers the identifier), move it to background (which schedules the task), and then use the debugger to test the launch ("e -l objc -- (void)[[BGTaskScheduler sharedScheduler]..."). However, if I then go back and change the identifier string in the target, plist, and app code, the debugger no longer launches the app in background. It doesn't issue any errors, but just doesn't run it. The change I made to the name is to add an "x" at the end of the string. If I change it back in the target, plist, and app, it works again just fine.
Posted
by dlshap.
Last updated
.
Post not yet marked as solved
3 Replies
537 Views
In ios17 and above, I can detect when swiftUI app goes into and out of background using: @Environment(\.scenePhase) private var phase ... .onChange(of: phase) { switch phase { case .background: print("entering background...") case .active: print("entering foreground...") default: break } } Is there a straightforward way to do this in SwiftUI for ios 16? I've found some examples using UIKit, but I am not that swift (sorry, couldn't resist) with that framework.
Posted
by dlshap.
Last updated
.
Post not yet marked as solved
0 Replies
387 Views
I've been working with swift and swiftui for about a year (but I'm old so not so swift (sorry)). I am trying to construct a predicate other than those supplied in the framework (i.e., name, email, phone) to fetch contacts having a specific value in their socialProfiles. For example, I want to fetch all contacts having a urlString that contains a specific value. I've finding the documentation on NSPredicate to be a bit daunting, especially since I have never used Objective-C, only swift. I think the problem is I don't know how to refer to the socialProfiles value in the predicate format string, nor what operators I should be using to filter. I'm sure the code below is totally wrong, and I'm not sure it can even be done, but to help illustrate what I'm trying to do: keys = [CNContactSocialProfilesKey] as [CNKeyDescriptor] predicate = NSPredicate(format: "SELF.socialProfile.value.urlString contains %@", value) do { let contacts = try store.unifiedContacts(matching: predicate, keysToFetch: keys) return contacts } Any suggestions would be appreciated, including: "You can't do that...you've got to retrieve all the contacts and filter them yourself"
Posted
by dlshap.
Last updated
.
Post not yet marked as solved
0 Replies
664 Views
If I have located (or created) a CNContact record on one device (e.g., iPhone), and I want to retrieve that same record programmatically from another device (e.g., iPad or Mac), is there any unique id that identifies that record? The identifier property on CNContact seems to be assigned for the local replica of the contact record, but I don't believe it can be used to retrieve the record on another device (e.g., using unifiedContact(withIdentifier...). I can unifiedContact(matching...) but not guaranteed to get same record if there are multiples with same predicate property values. I'm pretty new to Swift and CNContactStore, so sorry if I'm missing something obvious.
Posted
by dlshap.
Last updated
.