极光推送
1.导入极光SDK 官方文档
2.打开推送能力
- Application Target->Capabilities->Push Notifications,并开启
3.允许http传输
4.初始化
- 参照示例或官方文档引入头文件
- 参照示例实现系统推送的两个register方法,两个receive方法和jpush的两个代理方法
- 初始化实例的时候填入申请下的key
内置浏览器
- 拖入代码文件(UIViewController+Utils 和 WebController)
- 拖入相关图标素材
推送使用
1.使用后台进行推送
- 填写主、副标题
- 添加自定义参数,暂定"safari"为系统浏览器打开,"notsafari"为内置浏览器打开
{
"type" : "safari",
"targeturl" : "https://www.baidu.com/"
}
2.点击通知栏消息触发的方法
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
NSDictionary * userInfo = response.notification.request.content.userInfo;
if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
[JPUSHService handleRemoteNotification:userInfo];
[self doRemoteEvent:userInfo];
}
completionHandler();
}
3.根据参数执行具体的操作
- (void)doRemoteEvent:(NSDictionary *)userinfo {
NSString *url = [userinfo objectForKey:@"targeturl"];
NSString *type = [userinfo objectForKey:@"type"];
if ([url isKindOfClass:[NSString class]] && [type isKindOfClass:[NSString class]]) {
if ([type isEqualToString:@"safari"] ) {
NSURL *nsurl = [NSURL URLWithString:url];
[[UIApplication sharedApplication]openURL:nsurl options:@{} completionHandler:nil];
}else if([type isEqualToString:@"notsafari"]) {
WebController *webCtrl = [[WebController alloc]init];
webCtrl.url = url;
[[UIViewController currentViewController] presentViewController:webCtrl animated:YES completion:nil];
}
}
}