项目用到了极光推送
官方文档没有
自己百度了
测试OK
就集成进来了
1 导入SDK
2 桥文件导入
// 引入JPush功能所需头文件
#import "JPUSHService.h"
// iOS10注册APNs所需头文件
#import <UserNotifications/UserNotifications.h>
3 AppDelegate进行注册
func registerJPush(launchOptions:[UIApplicationLaunchOptionsKey:Any]?) {
if (UIDevice.current.systemVersionasNSString).floatValue >=10.0 {
let entity = JPUSHRegisterEntity()
entity.types = 0|1|2
JPUSHService.register(forRemoteNotificationConfig: entity, delegate:nil)
} else {
JPUSHService.register(forRemoteNotificationTypes:0|1|2, categories:nil)
}
JPUSHService.setup(withOption: launchOptions, appKey: JPushAppKey, channel: JPushChannel, apsForProduction: isProduction)
JPUSHService.setLogOFF() //关闭日志打印
}
4 AppDelegate代理方法
func application(_ application:UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken:Data) {
JPUSHService.registerDeviceToken(deviceToken)
}
// 前台模式收到推送数据
func application(_ application:UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable:Any], fetchCompletionHandler completionHandler:@escaping (UIBackgroundFetchResult) ->Void) {
JPUSHService.handleRemoteNotification(userInfo)
completionHandler(.newData)
let alertController =UIAlertController(title:"消息通知",
message:"您有一条消息请查看", preferredStyle: .alert)
let okAction =UIAlertAction(title:"查看", style: .default, handler: {
action in
print("点击了确定")
})
alertController.addAction(okAction)
UIApplication.shared.keyWindow?.rootViewController?.present(alertController, animated: true, completion: nil)
}
func application(_ application:UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable:Any]) {
JPUSHService.handleRemoteNotification(userInfo)
}
5 很重要的配置
6 清空角标
// 置空消息未读数量
JPUSHService.resetBadge()
UIApplication.shared.applicationIconBadgeNumber =0
7 注册标签 别名
// 注册极光推送别名/标签
JPUSHService.setTags(nil, alias: idStr,callbackSelector: nil, object: JPushManager.manager)