IOS,应用启动时如何处理多个本地通知? [英] IOS, how to handle multiple local notifications when app start?

查看:68
本文介绍了IOS,应用启动时如何处理多个本地通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个使用计时器的应用.假设用户可以设置多个定时器;对于这些计时器中的每一个,应用程序都会安排一个本地通知.当应用程序在前台运行或在后台运行时,我可以处理多个本地通知.我的问题是当用户设置多个计时器并然后终止应用程序(双击主页按钮并关闭应用程序).在这种情况下,当计时器到期时,所有相关的本地通知都会显示为横幅,并且应用程序图标徽章会增加.所以我想在用户从通知横幅启动应用程序或点击应用程序图标但使用

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

didFinishLaunchingWithOptions

我只能用

[launchOptions UIApplicationLaunchOptionsLocalNotificationKey]

[launchOptions UIApplicationLaunchOptionsLocalNotificationKey]

我需要处理所有定时器的所有本地通知!!我该怎么做?

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

推荐答案

您可以为每个本地通知添加一个 id,以便您知道应用是从哪个通知中触发的:

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

这篇关于IOS,应用启动时如何处理多个本地通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆