[关闭]
@binbins 2017-11-21T11:48:19.000000Z 字数 1408 阅读 157

极光推送接入


极光推送

1.导入极光SDK 官方文档

  • pod 'JPush'

2.打开推送能力

  • Application Target->Capabilities->Push Notifications,并开启

3.允许http传输

allow http.png

4.初始化

  • 参照示例或官方文档引入头文件
  • 参照示例实现系统推送的两个register方法,两个receive方法和jpush的两个代理方法
  • 初始化实例的时候填入申请下的key

内置浏览器

  • 拖入代码文件(UIViewController+Utils 和 WebController)
  • 拖入相关图标素材

推送使用

1.使用后台进行推送

  • 填写主、副标题
  • 添加自定义参数,暂定"safari"为系统浏览器打开,"notsafari"为内置浏览器打开
  1. {
  2. "type" : "safari",
  3. "targeturl" : "https://www.baidu.com/"
  4. }

2.点击通知栏消息触发的方法

  1. - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
  2. NSDictionary * userInfo = response.notification.request.content.userInfo;
  3. if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
  4. [JPUSHService handleRemoteNotification:userInfo];
  5. [self doRemoteEvent:userInfo];
  6. }
  7. completionHandler();
  8. }

3.根据参数执行具体的操作

  1. - (void)doRemoteEvent:(NSDictionary *)userinfo {
  2. NSString *url = [userinfo objectForKey:@"targeturl"];
  3. NSString *type = [userinfo objectForKey:@"type"];
  4. if ([url isKindOfClass:[NSString class]] && [type isKindOfClass:[NSString class]]) {
  5. if ([type isEqualToString:@"safari"] ) {
  6. NSURL *nsurl = [NSURL URLWithString:url];
  7. [[UIApplication sharedApplication]openURL:nsurl options:@{} completionHandler:nil];
  8. }else if([type isEqualToString:@"notsafari"]) {
  9. WebController *webCtrl = [[WebController alloc]init];
  10. webCtrl.url = url;
  11. [[UIViewController currentViewController] presentViewController:webCtrl animated:YES completion:nil];
  12. }
  13. }
  14. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注