2016-07-24 39 views

回答

0

在你的AppDelegate只需实现方法

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo; 
0

如果没有运行didFinishLaunchingWithOptions方法的应用程序被调用的应用程序启动时,你可以检查launchOptions参数是这样的:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 

    if (launchOptions != nil) { 
     NSDictionary *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; 
     if (notification) { 
      // Launched from push notification 
     } 

    } 
} 

如果应用程序已启动,则可以使用此方法:

- (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 
    } 
} 

你也可以检查: Detect if the app was launched/opened from a push notification

+0

如果应用程序已经启动,我需要处理这两个条件。 –

+0

如果应用程序从后台传到前台,同时如果应用程序收到推送通知,那么我会将状态设置为InActive。 (如何解决这个问题? –

相关问题