2

我可以找出在 iOS 上启动应用程序的事件吗?

我需要区分以下几点:

  1. 图标水龙头
  2. 横幅通知
  3. 警报通知

或者,我可以查看应用程序本地设置(设置为横幅或警报通知)吗?

4

1 回答 1

4

要确定应用程序是否通过按下通知启动,您需要实现 2 个方法。

首先,在应用程序 didFinishLaunchingWithOptions 中,执行以下操作:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
if ([launchOptions valueForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"]) {
 // Handle notification
}

第二:

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
if (application.applicationState == UIApplicationStateActive) {
    // The app was open when a remote notification was received...
} else {
    // The app was in the background and just came to the foreground in response to the user pressing the push notification
}

}

您可以使用以下方式查看已启用的通知类型:

UIRemoteNotificationType notificationTypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

但是,您无法区分横幅通知或警报通知。

于 2012-07-02T19:24:42.537 回答