I'm looking to implement notifications into my app. The app shares data over iCloud, and the notifications are saved in the iCloud-shared data. (It's a shoebox app.)
Unfortunately I don't have the resources to support push notifications.
According to this document:
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/WhatAreRemoteNotif.html#//apple_ref/doc/uid/TP40008194-CH102-SW1
The only type of push notification in OS X for non-running applications is icon badging.
Is this still the case? If so, that's okay - my running Mac application is already capable of (1) detecting iCloud changes, (2) determining if new local notifications need scheduling or existing ones need updating, and (3) scheduling them. So adding push support wouldn't be what I'm looking for anyway.
However - I'm wondering how to approach this from the iOS side of things. If I schedule a notification on my Mac, and this is saved to iCloud, how does my application on iOS receive a notification of this in the background?
If the iOS application is in the foreground, I can confirm that things work great. The iCloud notification is received, data is loaded, notifications rescheduled.
But if my application is in the background, or is not running at all, what is the best way to handle this? I understand the latter case is one I most likely have zero control over. But if the app is in the background, do I:
Need to spawn a background task to periodically check for data changes? Or,
Is there a notification I can subscribe to that will notify me only when iCloud data has changed?
I found the fetch
value for UIBackgroundModes
, but I'm not sure this is quite what I want - I'm not doing the fetching, I just want to respond, in the background, to iCloud changes.
Your options are limited. I think background fetch is actually a good alternative if you cannot afford remote notifications. With background fetch, your app will be woken up in relatively constant intervals and will be able to check if there are new notifications to display to the user (or notifications that have been removed, etc). Then you will be able to update the local notifications to match.
AFIK there isn't a great way to do what you're asking. Background Fetch might be a way to get some of what you want, but it won't give you any real control over when or how frequently it executes.
The correct mechanism to use is remote notifications.
I understand that you "don't have resources to support push notifications". Could you possibly consider a BaaS provider that offers a free tier, with push notification support? Both Parse and StackMob offer this, I believe.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With