iOS推送通知流程

时间:2016-11-13 08:03:32

标签: ios

我正在处理推送通知流程,但没有准确地知道如何处理它。我需要一个简单的解释,当推送通知到来时,该委托被称为

  1. 当用户点击推送通知标签
  2. 当推送通知到来时,用户点按应用程序图标
  3. 我无法维持我的应用程序申请状态,对我来说,流程应该是这样的:

    1. 当用户点按推送通知标签时:应该打开特定的viewcontroller
    2. 当推送通知出现时,用户点按应用程序图标:应该从应用程序进入后台打开相同的viewcontroller
    3. 如何在Xcode 8.1 / iOS 10.1.1中实现这一目标?

      我也使用后台模式远程通知和后台提取。

2 个答案:

答案 0 :(得分:1)

在AppDelegate.m中用它来检查用户点按图标的位置

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    //Handle notification when the user click it while app is running in background or foreground.
    if(application.applicationState == UIApplicationStateInactive) {

        NSLog(@"Inactive - the user has tapped in the notification when app was closed or in background");
        //do some tasks


    }
    else if (application.applicationState == UIApplicationStateBackground) {

        NSLog(@"application Background - notification has arrived when app was in background");

    }
    else {
        NSLog(@"application Active - notication has arrived while app was opened");

        //do tasks


    }


}

答案 1 :(得分:0)

当推送通知从服务器发送应用程序端的委托调用时,您必须通过添加registerForPushNotifications从应用程序端注册。

  - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
  { 

    //Handle notification when the user click it while app is running in background or foreground.


    //Where userinfo is a dict. It has the data sent from server

  }