jpush推送格式 swift_Swift JPush极光推送通知和自定义消息

在开始之前,首先了解下自定义消息和通知的几点区别。

自定义消息和通知的区别

收到推送自定义消息时推送通知栏不显示

自定义消息推送不经过APNS,所以说跟推送证书没有关系

只有app在前台时才能收到自定义消息,未启动或者启动但处于后台时接收不到(解决了不想在app未启动时收到推送消息的问题)

SDK初始化

Appdelegate文件

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

// 极光推送

if (UIDevice.current.systemVersion as NSString).floatValue >= 10.0 {

if #available(iOS 10.0, *) {

let entity = JPUSHRegisterEntity()

entity.types = NSInteger(UNAuthorizationOptions.alert.rawValue | UNAuthorizationOptions.badge.rawValue | UNAuthorizationOptions.sound.rawValue)

_ = JPUSHService.register(forRemoteNotificationConfig: entity, delegate: self)

} else {

// Fallback on earlier versions

}

} else if (UIDevice.current.systemVersion as NSString).floatValue >= 8.0 {

//可以添加自定义categories

JPUSHService.register(forRemoteNotificationTypes: UIUserNotificationType.badge.rawValue | UIUserNotificationType.sound.rawValue | UIUserNotificationType.alert.rawValue, categories: nil)

} else {

//categories 必须为nil

JPUSHService.register(forRemoteNotificationTypes: UIUserNotificationType.badge.rawValue | UIUserNotificationType.sound.rawValue | UIUserNotificationType.alert.rawValue, categories: nil)

}

var isJpushProduction: Bool

#if DEBUG

isJpushProduction = false

#else

isJpushProduction = true

#endif

JPUSHService.setup(withOption: launchOptions, appKey: JPUSHService_appKey, channel: "Publish channel", apsForProduction: isJpushProduction, advertisingIdentifier: nil)

return true

}

通知(极光远程推送)

调用此 API 来取得应用程序对应的 RegistrationID。 只有当应用程序成功注册到 JPush 的服务器时才返回对应的值,否则返回空字符串。

func application(_ application: UIApplication, didRegisterFo

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值