问题
I know that this topic is a duplicate, but I need your help. It is very important for me and the other posts have no really an solution for me.
I have an app (Swift 2) where the user can save entries in core data. These entires will show in a table view.
The user has to set an reminder date (with a date picker) for each entry. This date will use for the fire date of the local notification. Each entry get 2 local notifications
First fire date: 1 week before the chosen date, second fire date: chosen date
The problem is the Apple limitation of 64 local notifications. The user can only save 32 entries (32 entries * 2 notifications = 64 notifications)
How can I solve this problem with the limitation?
I know that I can set "reminder" into the Apple calendar instead of local notifications. But this doesn't looks good - this shouldn't be the solution.
I know that I can check on each app start or in the method did receive notification, which notifications should set next. but for this I have to trust, that the user start the app or tap on the received notification. If he or she doesn't do this for a few days => no new notification will set and he or she doesn't get the next notification. This solution isn't very safe.
回答1:
You could routinely send a push notification to devices that have not contacted the backend in some time and have the remote notification handler setup local notifications up to the limit, see application(_:didReceiveRemoteNotification:fetchCompletionHandler:).
Or, you could setup a background fetch that reschedules local notifications up to the limit using, see application(_:performFetchWithCompletionHandler:). Note that you cannot fully control how often this refresh is performed, but in my experience it is called up to a number of times a day.
When using either one of the above method, you can update local notifications even if the user never opens the apps.
回答2:
I also had some kind of problem like this. So what I did is that I planned the notifications as much as possible, and when there is room to plan more notifications then I planned more notification.
UIApplication.sharedApplication().scheduledLocalNotifications?.count
You can get the number of planned notifications. Subtract it from 64 and plan remaining notifications.
In applicationWillEnterForeground
you can do this -
if UIApplication.sharedApplication().scheduledLocalNotifications?.count < 64
{
//refersh list
let nc = NSNotificationCenter.defaultCenter()
nc.postNotificationName(Constants.SCHEDULE_MORE_NOTIFICATION, object: nil)
}
So your notification list will be refreshed automatically.
来源:https://stackoverflow.com/questions/35694804/ios-limitation-of-64-local-notifications