2016-07-24 36 views

Antwort

0

implementieren Sie einfach Ihre AppDelegate die Methode

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

Ist die Anmeldung nicht die didFinishLaunchingWithOptions Methode ausgeführt wird, wenn die Anwendung gestartet wird aufgerufen, und Sie können die launchOptions Parameter wie folgt überprüfen:

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

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

    } 
} 

Wenn die Anwendung bereits gestartet wurde, können Sie diese Methode verwenden:

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

Sie können auch überprüfen: Detect if the app was launched/opened from a push notification

+0

Was ist, wenn die Anwendung bereits gestartet wird, muss ich beide Bedingungen behandeln. –

+0

Wenn App von Hintergrund zu Vordergrund kommt, zur gleichen Zeit, wenn App Push-Benachrichtigung erhalten, würde ich den Status als InActive erhalten. (Wie löst man das? –