Post

Replies

Boosts

Views

Activity

Timer driven refresh
I have an app that needs to refresh a server whenever a Contacts record is updated. I can observe Contacts, but that only seems to work when my app is running (and in foreground, which it cannot be on iPhone if the Contacts app is being updated). I want it to process, even if my app is in background, or has been terminated (swiped away), or after a phone restart. The only way I can think of is to periodically push a notification to the app from an external server. Is there any way to run a timer that sends a notification to the app on a periodic basis? The timers you can set seem to run even if the Clock app is swiped away, or following a phone restart. Is there anything like that I could use to wake my app periodically?
1
0
220
Oct ’24
Best way to wake app to sync data
If I have data on server that is updated periodically (e.g., daily or weekly), and I want to have that data sync'd to iOS app, what is best way? I want to make sure it will get updated when app is in foreground, background, swiped away (terminated), or following a phone restart. The two ways I'm thinking of are PushKit and User Notifications. I'm currently using User Notifications, but I am finding that sometimes the notification doesn't get processed (haven't yet determined reliable conditions for duplicating this problem). I'm mainly wondering if, given the use case (occasional updates that ideally are processed in background ASAP), this is the best approach.
3
0
176
Oct ’24
How to read APS Environment entitlement
Is there a simple way to get the value of the APS Environment setting in the Entitlements file from within a SwiftUI app? As others have noted, when the app is run from Xcode, this value is set to "development" but when run from Archive'd TestFlight version, it is set to something else (presumably "production"). I need to know which environment the app should use for registering its device token for notifications.
1
0
494
Jun ’24
Detect foreground/background change
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.
6
0
1.7k
Jan ’24
Can't change background task identifier
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.
12
0
929
Jan ’24
Is it possible to fetch contacts from CNContactStore using custom predicate?
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"
1
0
600
Oct ’23
Identify CNContact record from multiple devices
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.
0
0
795
Jun ’23