0

Apple doc在后台引起用户注意

通知是应用程序暂停、在后台或未运行以引起用户注意的一种方式。

由于区域监控,我的应用程序被 iOS 唤醒is in the background并发布本地通知。用户点击通知,应用程序将在前台。

由于用户点击了通知,如何确定应用程序进入前台?

哪个委托方法将包含通知信息。

didFinishLaunchingWithOption or didReceiveLocalNotification
4

3 回答 3

1

如果您的应用程序在后台运行并且您在 LocalNotification Banner 上被点击,那么您将被调用以下方法:

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

iOS 8 之后:

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void(^)())completionHandler

如果应用程序未在后台运行,您将在以下位置收到通知:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
if ([launchOptions valueForKey:@"UIApplicationLaunchOptionsLocalNotificationKey"]) {
 // here you will get
}
于 2016-06-21T04:58:33.607 回答
1

当 UILocalNotification 被触发时,您可以检测到您的应用程序的状态是什么,如果 - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification 被调用,这将确保收到本地通知。

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
    UIApplicationState state = [application applicationState];
    if (state == UIApplicationStateInactive) {
        // Application was in the background when notification was delivered.
    } else {

    }
}
于 2016-06-21T05:18:54.400 回答
0

您可以通过使用 application.applicationState 来确定这一点

 if(application.applicationState == UIApplicationStateInactive)
     {
           NSLog(@" Inactive");
      // when you tapping on notification

     }
    else if (application.applicationState == UIApplicationStateBackground)
    {
           NSLog(@" background");
    }
    else
    {
          NSLog(@" Active");

    }
于 2016-06-21T05:55:02.387 回答