Swift3.0 极光推送

前提

本文目的是方便以后自己查看,还请各位朋友高抬贵手、不喜勿喷,谢谢🙏🙏🙏

一、极光推送通知

1.当app处于后台(当前为桌面或者使用其他应用时)

app收到通知时,通知栏正常显示通知,但是没有方法来接收发送的消息。当点击通知时,会跳到app里面,这时有执行接收消息的方法:func jpushNotificationCenter(_center:UNUserNotificationCenter!, didReceive response:UNNotificationResponse!, withCompletionHandler completionHandler: (() ->Void)!);

2.当app处于前台

app收到通知时,通知栏正常显示通知,这时有执行接收消息的方法:func jpushNotificationCenter(_center:UNUserNotificationCenter!, willPresent notification:UNNotification!, withCompletionHandler completionHandler: ((Int) ->Void)!);当点击通知时,这时有执行接收消息的方法:func jpushNotificationCenter(_center:UNUserNotificationCenter!, didReceive response:UNNotificationResponse!, withCompletionHandler completionHandler: (() ->Void)!);

二、极光推送自定义消息

1.当app处于前台、后台(app没有销毁,处理情况一样)

app收到通知时,是没有通知显示的,需要自己添加本地通知,后面会有介绍,这时有执行接收消息的方法:func networkDidReceiveMessage(notification:Notification);当点击通知时,这时有执行接收消息的方法:func jpushNotificationCenter(_center:UNUserNotificationCenter!, didReceive response:UNNotificationResponse!, withCompletionHandler completionHandler: (() ->Void)!);

三、添加本地通知

这里添加一张示例截图,代码不多,以供参考。

四、推送通知方法

1.iOS 6以下

基于iOS 6 及以下的系统版本,如果 App状态为正在前台或者点击通知栏的通知消息,那么此函数将被调用。可通过AppDelegate的applicationState是否为UIApplicationStateActive判断程序是否在前台运行。

func application(_application:UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable:Any])

2.iOS 7以上且10以下

基于iOS 7以上且10以下的系统版本,使用Remote Notification 特性那么处理函数需要使用

func application(_application:UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable:Any], fetchCompletionHandler completionHandler:@escaping(UIBackgroundFetchResult) ->Void)

3.iOS 10以上

基于iOS 10及以上的系统版本,原didReceiveRemoteNotification将会被系统废弃,由新增UserNotifications Framework中的func userNotificationCenter(_center:UNUserNotificationCenter, willPresent notification:UNNotification, withCompletionHandler completionHandler:@escaping(UNNotificationPresentationOptions) ->Void)或者func userNotificationCenter(_center:UNUserNotificationCenter, didReceive response:UNNotificationResponse, withCompletionHandler completionHandler:@escaping() ->Void)方法替代。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容