3

使用 UILocalNotification 应用程序打开时,应用程序委托中的此功能被触发:

 - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{

但是当应用程序关闭并且不在后台时,它会在我点击通知按摩时启动应用程序,但它不会触发此方法。

我需要开火,因为她是带我去另一个场景的人——当有人收到通知时我需要展示它。

仅当她在后台时才有效。

4

2 回答 2

6

你必须实施application:didFinishLaunchingWithOptions:. 通知将是选项之一。

- (BOOL)application:(UIApplication *)application 
  didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
    if (notification) {
        // handle your notification here.
    }
}
于 2012-08-28T15:24:50.183 回答
5

从规格:

If the action button is tapped (on a device running iOS), the system 
launches the application and the application calls its delegate’s    
application:didFinishLaunchingWithOptions: method (if implemented); it passes 
in the notification payload (for remote notifications) or the local-notification 
object (for local notifications).

换句话说,application:didReceiveLocalNotification仅当您发现应用程序正在运行时。

如果应用程序由于本地(或远程)通知而启动,则通知中的商品将传递到application:didFinishLaunchingWithOptions:方法中,这就是您捕获的地方。

于 2012-08-28T15:28:11.120 回答