iOS 10 及以上系统,采用以下方法:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14@available(iOS 10.0, *) func jpushNotificationCenter(_ center: UNUserNotificationCenter!, willPresent notification: UNNotification!, withCompletionHandler completionHandler: ((Int) -> Void)!) { // 前台通知,JPUSH socket直连 let userInfo = notification.request.content.userInfo // 在这里处理推送消息 if let trigger = notification.request.trigger, trigger.isKind(of: UNPushNotificationTrigger.self){ #if arch(arm) || arch(arm64) JPUSHService.handleRemoteNotification(userInfo) #endif } completionHandler(Int(UNNotificationPresentationOptions.alert.rawValue)) }
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14@available(iOS 10.0, *) func jpushNotificationCenter(_ center: UNUserNotificationCenter!, didReceive response: UNNotificationResponse!, withCompletionHandler completionHandler: (() -> Void)!) { // 点击通知,无论App进程是否为杀死状态 let userInfo = response.notification.request.content.userInfo // 在这里处理推送消息(点击推送消息进入应用) if let trigger = response.notification.request.trigger, trigger.isKind(of: UNPushNotificationTrigger.self){ #if arch(arm) || arch(arm64) JPUSHService.handleRemoteNotification(userInfo) #endif } completionHandler() }
iOS 10以下系统,采用以下方法:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) { if application.applicationState == .active{ // iOS 10以下,前台 // 在这里处理前台推送消息 }else{ // iOS 10以下,后台,且进程未终结 // 在这里处理后台推送消息(点击推送消息进入应用) } #if arch(arm) || arch(arm64) JPUSHService.handleRemoteNotification(userInfo) #endif }
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13// App进程已终结,启动App进程 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool{ if #available(iOS 10, *) { // iOS 10及以上,不处理此消息 }else{ // 如果系统是iOS 10以下时,解析消息内容 if let remoteNotification = launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] as? [AnyHashable : Any]{ // 在这里处理推送消息(点击App图标启动应用) } } }
最后
以上就是含蓄仙人掌最近收集整理的关于iOS 极光推送消息跳转处理总结的全部内容,更多相关iOS内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复