How can a sync of IOS reminders programmatically be triggered / forced? - ios

I am writing a task mgmt app that is using EKReminder.
Works perfectly when using on one iOS device.
When I use on two devices (same apple account), I realise that reminder changes sync is with significant delay and even often incomplete. (tried iCloud, google, company outlook)
This thus seems unrelated to my app (same happens if I change reminders directly in Reminder iOS app).
Can I programmatically force a sync of reminders with whatever service (e.g. iCloud) that they are linked to and trigger this out of my app?

#Losiowaty suggests a valid solution in the comments to the question, but I think there's a bit more information the following solution(s) could provide. To be fair, I have actually noticed this exact same issue specifically with the Apple Reminders app, and think that in general the solution applies to iOS but could carry over to the same notifications that have similar issues on macOS as well.
For iOS, though, the issue seems to be:
Two iOS devices on the same Apple iCloud account will both get a specific Reminder push notification. The issue is, though, that clearing that push notification on 1 device does not sync the second device properly in almost all cases as of right now. This is the question asked above's context, from what I understand.
The second, not as well recognized problem, from what I can tell, is that this problem is due to the fact the "host" application isn't properly clearing it's own push notifications, so to speak. What I mean by this is:
iPad and iPhone receive push notification from Reminders app about a 12:00 TODO item, at 12:00.
iPad push notification is acted on, marked as completed, and cleared on iPad immediately
iPhone push notification is still there (the issue we're attempting to solve), but will likely not be removed until itself is removed (opening Reminders app not from the push notification will often not clear this).
The reason for this is the push notification isn't being cleared by the application, and so even though it's now irrelevant information (since it was cleared after being marked as completed (or snoozed) on another device), but the push notification system doesn't know that (since pushes are just payloads of information, unless you properly use TTL on these, but that's a different answer). The way to fix that, that most/some apps use to an extent, could be:
1) As stated in the comment, in bullet point 2 the action (marked as completed, and cleared from device 1) could update the backend (iCloud in this case) that this item is complete, which then sends a silent push to all associated devices which properly clears the push notification (this would likely happen in a form of an application background task, something like a Notification Service Extension Apple link here (iOS 10+ only)
2) Another method would be to keep an internal "secret" key unique to each push notification you send (across all associated devices). You can then associate any one "task" object (in the Reminders app context as an example, but this can really be any data object held in your app) with a set of push notification "secret" keys (which can expire on a custom timer if you feel these are getting out of hand, especially since pushes will likely be viewed OR irrelevant after 30 days in most use cases). From this, along with a mechanism to make the application update it's data, if the app notices the device has any push notifications it shouldn't (based on the set of "secret" keys which are associated with "active" data), it should clear them for you. This ends up with the same result as method 1, but doesn't require a silent push (a socket can be used, or something else entirely), and could rely on a basic background job
It looks like either way, you need some kind of background task processing to act when something happens (either through a notification service extension as linked or through a simple background task that Apple supports).
I hope this answers your question and points you in the right direction for what you are building!

Related

What is the best way to keep updated the info of an iOS App?

Since push notifications may not be delivered sometimes (you can lose a few of them), you can not run code after the iPhone is turned on to check if there is new information available from the server, and you can not run code if your iOS App is closed... What can you do if you want to be as more accurate as possible in for example a Chat App in iOS?
I mean, inform the user as faster as possible that he has new info available. Comparisons: WhatsApp is updated without any delay.
You can do background fetch if your App is in background. But if the App is closed and you miss a push, it's not going to be up to date until the next push arrives or user opens the App. The same with silent notifications. If the app is terminated by the user, you are not going to receive it. Is there any way to solve it? It must be because other Apps do it... If there is any "private and secret" API that they are using (I read about this answer when no one know how to do that)... Is there any way to apply to use it?
UPDATE:
I'm using push notifications. The goal is to fix when a push doesn't arrive. Example: User A send chat message to user B. User B doesn't have the App open. The system lose the push. User B is not going to receive the message until he open the App.
Push notifications seems to be your only way even if you do loose a few of them, which I don't know how you would since they are pushed to apples secure server... but what do I know. As long as the user turns on the push notifications you should be fine. They may be delayed due to apples way of handling them. Honestly push seems to be the future, having your app constantly every minute or two check for new messages is a huge battery water in conjunction with normal texting apps. Your app should provide the best live data but since apple restricts to push notifications when the app is off or not running just stick to push notifications and only push major events to the user. I believe you can set up a job scheduler using quartz or schedulator to setup your server to push notifications to your app.

IOS/Android app custom push notification handling

I want to develop an app, but before I actually start developing, I've been doing some research so that i can be sure it's going to work in the way I'd like to do this.
You can imagine the app as a kind of news app, where the user can indicate whether he wants to receive push notifications, and may also indicate that he only wants to receive a push notification if it is in X distance from his current location.
And this is probally a problem on IOS, On android it would be no problem if a push notification came in to read the current position of the user and settings and then show the push notification or not.
As far as I've read this is a problem on iOS, the system receives the push and the app can not respond to it unless the user clicks on it.
Theres also another problem about closing an app on IOS, ideally a app should not be closed (swiped out) by the user because this would be a force close on IOS.
From ive seen most users still swipe out apps, and this would mean that my app cannot run background tasks anymore.
This is what i thougt about:
Send Silent push, app download data on the background -> Check if this meets the user settings, if so show a local notification. (30 sec time to handle, but do not know if it is possible to throw a local push here too.)
The app sends data on the background over the user's current position before sending a push, the server checks for which apps it should be sent (actually no solution, too much data usage as it may be that the user is only one Specific location, need a good server if the app is used on thousands of devices.).
Does anyone have any idea how to handle this problem?

Should I use Apple Push Notification or simply pull data in background for simple app?

I have an app that fetches data from server via json/http (actually, it synconizes data with Core Data). User needs to be notified when new data is available in 5-10 minutes. I am planning to have about 10 users (that as an internal enterprise app), so I can simply fetch data in background using NSURLSession.
But iOS may kill my app in case of low memory (or even user may kill it!), and no notifications would be delivered! So, I believe APN may be used. But this solution looks very complex for such a simple task and small number of users.
Ideally, I should have some service/daemon or (like IntentService on android), but I can't have it on iOS, so there are only 2 ways: APN or background app (which may be killed). What is the right way here?
Even if your app killed, your app can be opened in background and fetch data. This feature is called as background app refresh. After updating data, you can show user a local notification, which makes it easy by not using APNS. However, if you want to use APNS, you can use Amazon SNS to send push notifications. If i am not remembering wrong, it gives first million push notifications as free for every month. It is very easy to implement, though.

Is Silent Remote Notifications possible if user has disabled push for the app?

In my settings tabbar:
I have a feature specific switch which can be turned OFF or ON based on API response.
From website only admin is authorized to turn ON/OFF.
I can make /user API call everytime on settings tap to check the current settings for the user but there are couple of disadvantage like if user is already on setting then it will not update the UI and calling api everytime on settings tap doesn't sounds a perfect solution.
I think better solution is to send a silent push notification which i can use to make the API call to update the settings UI whenever needed.
But if user has disabled the push notification will I still receive silent push ? What is the recommended approach to handle such situations ?
Short answer, yes
The exciting new opportunity for app developers in iOS 8 is that Apple will now deliver “silent” pushes even if the user has opted out of notifications. Also, “silent push” is no longer just for Newsstand apps. Every app can take advantage of this ability to refresh content in the background, creating the most up-to-date, responsive experience possible, the moment the user opens the app.
Although...
Users still have the ability to switch off your app’s ability to process a “silent push” by means of the “Background App Refresh” control. Even though Apple Push Notification service (APNs) will deliver a push marked “content-available” to your phone, the OS will not wake up your app to receive it, effectively dropping it on the floor. However, opting out of “Background App Refresh” is a lesser-known capability not directly associated with Notifications. You don’t access this preference in your Notifications Settings--it’s located under General > Background App Refresh screen.
Keep this in mind when building your application.
Source:
https://www.urbanairship.com/blog/watch-list-ios-8-opt-in-changes
This matrix might help. At left hand side, it shows if "didReceiveRemoteNotification: " method will get called or not. Other two columns is related to setting app. Settings -> YourApp. If yourApp supports Notifications and background app refresh. Look into matrix to check when you app will receive silent push.
Other answers are good. But they are not official answers.
The official answer is in What's New in Notifications WWDC 2015 video:
Silent notifications are enabled by default. The user does not need to
approve your -- does not give permission to your app to use them, and
you can just start using them without asking the user for permission.
But silent notifications are the mechanism behind background app
refresh. At any point you know that the user can go in settings and
disable them. So you can't depend on them always being available. You
don't know if the user the turn them off, and you are not getting a
notification anymore. This also means that silent notifications are
delivered with the best effort. That means that when the notification
arrives on the user's device, the system is going to make some
choices.
For more see this image and this answer

How to fire an event on uninstallation of an iphone app?

On uninstallation of an iphone app.I want to delete all the data from my database serve
this can be possible but I dont think there is a very simple way like implementing a method when user removes your app. you can take a look in APNS Feedback Service , this might help you.
If a provider attempts to deliver a push notification to an
application, but the application no longer exists on the device, the
device reports that fact to Apple Push Notification Service. This
situation often happens when the user has uninstalled the application.
If a device reports failed-delivery attempts for an application, APNs
needs some way to inform the provider so that it can refrain from
sending notifications to that device. Doing this reduces unnecessary
message overhead and improves overall system performance.
For an iOS app, remove option which comes after long pressing on icon is the only 'uninstalling' option which will always remove any stored date of the app from device. There will not be any particular event triggered when user does that.

Resources