IOS推送通知流

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (41)

我正在研究推送通知流,但没有确切地了解如何处理它。我需要一个简单的解释,当推送通知出现时,调用哪个委托

  1. 当用户点击推送通知标签时
  2. 当用户点击App图标时,推送通知来了

我无法维护我的应用程序状态,对我来说,流应该是这样的:

  1. 当用户点击推送通知标签时*它应该打开特定的视图控制器。
  2. 当用户点击App图标时,推送通知来了:它应该从应用程序的背景位置打开相同的视图控制器。

如何在Xcode 8.1/IOS 10.1.1中实现这一点?

另外,我还使用后台模式、远程通知和后台提取。

提问于
用户回答回答于

当推送通知从服务器在应用程序端发送一个委托调用时,必须从APP端通过添加RegistrerForPushNotiments注册。

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

  }
用户回答回答于

在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


    }


}

扫码关注云+社区

领取腾讯云代金券