If I create a CKRecord using CKDatabase.saveRecord, no CKSubscription notification is triggered when that record is inserted by myself. Apparently I only get notifications if somebody else inserted a record, but I'd like to uniformly receive notifications, regardless if the record was created by me or somebody else.
Also I didn't find a mention about this behavior in the docs.
I tried for ages to receive notifications after creating the record on the same device, but it only finally worked if i created an artificial record in the dashboard.
Is there a flag to change this behavior?
You only receive subscription notifications for records created, deleted or modified off the device. If you insert/change/delete a record on your device you need to handle this directly.
From the Cloud Kit Quick Start guide (emphasis added)
Test Subscriptions
You can initially test subscriptions by running your app through Xcode and using CloudKit Dashboard to create, modify, or delete records, as described in Add, Modify, and Delete Records. Then fully test subscriptions by running your app on multiple devices. Use one device to make changes and another device to receive the subscription notifications. You use multiple devices because a notification isn’t sent to the same device that originated the notification
Related
I have added date triggered local notifications to my app and now I want the user to be able to get the notification they set on one device on all of their devices that have the app. I save the notification they set in a core data entity (saving the notifcation identifier and date it's suppose to be triggered). The app uses a NSPersistentCloudKitContainer to sync the users devices together.
Since I save the notifications the user sets to this iCloud container, is there a way I can listen to iCloud changes in the app's background so when a notification is added in iCloud, I can read it and set it as a local notification on their other devices?
You can think of this as a user setting a reminder in the Apple reminders app and how that notification pops up on all of my iCloud devices at the time I set it at. I prefer to not make any type server to handle this because I am not familiar with using servers.
Thank you in advance for your help!
Yes, it is possible for NSPersistentCloudKitContainer to sync while your app is the background, and you can react to those changes by listening to any of these notifications: NSManagedObjectContextObjectsDidChange, NSPersistentCloudKitContainer.eventChangedNotification, and NSPersistentStoreRemoteChange (if enabled). There are some important caveats:
iOS may schedule an import to occur with a utility priority, which may or may not execute eventually.
This does not occur when your app is not running as the remote change notifications are non-launching, so for example, if you restart the device sync will not occur until you open the app again. Perhaps you could schedule background tasks to periodically attempt sync to try to keep up-to-date - I have not tried this.
This does seem to be working more reliably in iOS 16 vs 15 in my testing. I've documented my findings in the dev forums.
I am fairly new to iOS development and wanted to know if my concept of how to set up and use push notifications on iOS.
So my general idea is that on each time the iOS app is opened (following Apple's guidelines) to register for push notifications and then handle the did register and failed to register methods. In the did register for push notifications I would post to my webserver the device id which I would store in the database with a last connected date.
The logic on the webserver side would be to update the existing record if the device id already exists to update the last connected date (there will be a cron job that purges device ids where they haven't been connected in the last 3 months say).
So once I have the device ids that are fairly current then I can iterate through these device ids when sending the push notifications, this way I won't be sending unnecessary pushes to devices that may not have the app installed any more.
Does this concept sound correct?
This should let you understand.
I have a small messaging app and user receives a push notification whenever the user gets a message. Recently I have implemented Realm Database for my app. I am storing all the data that comes from the server into the realm directly and displaying the data to the user from realm. So, after shifting to this way the push notifications are not working. But again if I download the current version that is in the AppStore, the notifications are working. Every message has a messageID and we are sending the messageID as one of the parameter in the push notifications. Can someone help me on what I can do to make the push notifications working again.
Well, for getting push notifications to work, you not only need to configure the app correctly, you also need to configure the backend service & APNS linking correctly to get it to work.
You should try a methodical approach wherein you divide the entire feature implementation of push notifications into smaller sub-tasks like app side logic, backend configuration, Certificates & Provisioning Profile setup, etc. Try to examine each of these sub-task implementation & surely you would find the culprit. Since, you know the existing App Store version of the app is working,you have your task reduced
So in iOS 10 you can now write notification service extensions that "intercept" push notifications so that you can download stuff and handle them before displaying them to the user.
However they require that the push payload has the 'mutable-content' key in aps set to 1. CloudKit subscriptions do not seem to return this key in the userInfo dictionary (At least CKDatabaseSubscription doesn't), and so the service extension doesn't get called.
Is there a way to get CloudKit subscription notifications to work with UNNotificationServiceExtensions?
This is now possible in iOS 11, look for the shouldSendMutableContent property in CKNotificationInfo
Currently, this does not appear to be possible.
(There is a post on Apple's forums where a developer suggests that someone create this as a feature request. Someone already did, I plan on duplicating the request.)
Is there any way to get a notification when the user uninstalls my networked IPhone app, preferably including some custom data from the app's preferences like the user ID?
What I'm trying to do is to automatically delete the user's data from the server backend when they delete the app.
The only thing like this is the feedback service of Apple Push Notifications. So, if you're using push notifications and you can readily recreate the user's data if they reinstall the app, you can use the feedback service as a trigger mechanism for cleaning up your user database. Just make sure that all devices associated with the user record have deleted the app before doing this.
I think you have only approach - it is to set user data expiration time.
Check last user activity time using:
Push Notification Sending error (see #warrenm post)
or time when user had access to your services
or use log services like BugSence or TestFlight to do the same