IOS, how to handle multiple local notifications when app start?

时光总嘲笑我的痴心妄想 提交于 2020-01-05 05:46:09

问题


I'm creating an app that uses timers. Let's say that the user can set multiple timers; for each of those timers the app schedule a local notification. When the app is running in foreground or is in background i have no problem handling multiple local notifications. my problem is when the user set multiple timers and then terminate the app( double click on home button and close the app). in that case, when timers expire all relative local notifications are shown as a banner and the app icon badge is incremented. so i want to handle all of those notifications when the user start the app from notification banner or tapping on app icon but using

didFinishLaunchingWithOptions

I am able to handle only one notification with

[launchOptions UIApplicationLaunchOptionsLocalNotificationKey]

I need to handle all local notifications of all timers!! how can i do that?


回答1:


You can add an id to each local notification so you know from which notification was the app triggered:

localNotification1 = [[UILocalNotification alloc] init]; 
localNotification1.userInfo = @{ "type" : @1 };
...
localNotification2 = [[UILocalNotification alloc] init]; 
localNotification2.userInfo = @{ "type" : @2 };

http://developer.apple.com/library/ios/documentation/iPhone/Reference/UILocalNotification_Class/Reference/Reference.html#//apple_ref/occ/instp/UILocalNotification/userInfo



来源:https://stackoverflow.com/questions/19677471/ios-how-to-handle-multiple-local-notifications-when-app-start

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!