是否可以通过推送通知知道应用程序是否已启动/打开?
我想启动事件可以在这里捕获:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { if (launchOptions != nil) { // Launched from push notification NSDictionary *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; } }
但是,当应用程序在后台时,我如何检测它是从推送通知中打开的?
请参阅此代码:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { if ( application.applicationState == UIApplicationStateInactive || application.applicationState == UIApplicationStateBackground ) { //opened from a push notification when the app was on background } }
如同
-(void)application:(UIApplication *)application didReceiveLocalNotification (UILocalNotification *)notification