我可以找出在iOS上启动应用程序的事件吗?
我需要区分以下几点:
或者,我可以查看应用程序本地设置(为Banner或警报通知设置)吗?
答案 0 :(得分: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];
但是,您无法区分横幅广告或警报通知。