个推测试透传消息,个推网站测试只支持透传消息
创建推送—透传消息
目标平台:iOS开发环境
透传内容
描述:测试页面跳转4
消息内容:{“tk1”:”tv1”,”tk2”:”tv2”}
定速推送:关闭
展示条件:无
APN参数设置
模式选择:iOS设置
content-available:0 (app在线推送透传消息,不在线就推送apns消息)
title: test444
body: body444
badge:1
sound:默认
payload:与消息内容一致
iOS多媒体推送:否
category:category1
title-loc-key:title-loc-key1
title-loc-args:title-loc-args
loc-args:loc-args
loc-key:loc-key
category:
title-loc-key:
title-loc-args:
loc-args:
loc-key:
launch-image:select
subtitle-loc-key1:subtitle-loc-key1
subtitle-loc-args:subtitle-loc-args1
subtitle:subtitle
apns-collapse-id:apns-collapse-id1
action-loc-key:action-loc-key1
目标选择:全部用户
推送设置
推送方式:即使
消息有效期:是
有效时长:2小时,该时间段内CID在线过的用户均可收到通知。(0-72小时内的正整数)
一:用户不在线:用户在手机系统消息栏可以看到信息:
艺享优选
test444 [modified]
subtitle
body444
只所以看到modified是因为这个复制的个推测试消息。只能看到这些字段,其它推送的消息字段。
二:点击系统的推送消息激活app,在didFinishLaunchingWithOptions函数通过NSDictionary* message = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];获得的消息日志文件记录的日记如下:
AppDelegate.m:AppDelegate.m:-[AppDelegate application:didFinishLaunchingWithOptions:]:37 Verbose:didFinishLaunchingWithOptions message:{ "_ge_" = 1; "_gmid_" = "GT_0824_32bba9e07271dbcfd39a3dc85d014fa2:b0777f08-24aa-16567d8f1d0-1466927070:4790715966c94d93e84182fbfce36182"; "_gurl_" = "sdk.open.extension.getui.com:8123"; aps = { alert = { "action-loc-key" = "action-loc-key1"; body = body444; "launch-image" = select; "loc-args" = ( "loc-args" ); "loc-key" = "loc-key"; subtitle = subtitle; "subtitle-loc-args" = ( "subtitle-loc-args1" ); "subtitle-loc-key" = "subtitle-loc-key1"; title = test444; "title-loc-args" = ( "title-loc-args" ); "title-loc-key" = "title-loc-key1"; }; badge = 1; category = category1; "mutable-content" = 1; sound = default; }; payload = "{\"tk1\":\"tv1\",\"tk2\":\"tv2\"}";}
可见,点击消息激活应用时,只传递过来部分参数,并费所有字段,至少body的键值对就没有传递过来,由于设置的payload的属性是与消息内容一致,所以通过payload字段间接获取到了body的键值对。
当然你设置payload为自定义(例如设置内容如:jump)。这是的日志变成:
AppDelegate.m:AppDelegate.m:-[AppDelegate application:didFinishLaunchingWithOptions:]:37 Verbose:didFinishLaunchingWithOptions message:{ "_ge_" = 1; "_gmid_" = "GT_0824_02819c75c17adf33e6faa43842072025:b0777f08-24aa-16567d8f1d0-1455623540:4790715966c94d93e84182fbfce36182"; "_gurl_" = "sdk.open.extension.getui.com:8123"; aps = { alert = { "action-loc-key" = "action-loc-key1"; body = body2; "launch-image" = select; "loc-args" = ( "loc-args" ); "loc-key" = "loc-key"; subtitle = subtitle; "subtitle-loc-args" = ( "subtitle-loc-args1" ); "subtitle-loc-key" = "subtitle-loc-key1"; title = test2; "title-loc-args" = ( "title-loc-args" ); "title-loc-key" = "title-loc-key1"; }; badge = 1; category = category1; "mutable-content" = 1; sound = default; }; payload = jump; }
三:应用在线,收到透传消息的消息,系统栏不显示推送的消息:
>>>[GexinSdk ReceivePayload]:taskId=GT_0824_6df34b352b517e4766883c2b3cf138bd,messageId:28ae7ef0-bc-16567df2b2d-1482748620,payloadMsg:{"tk1":"tv1","tk2":"tv2"}
可见只收到了body的键值对,其它设置的字段都没有收到。
点击系统消息进入对应app页面的基本逻辑可以通过下面的代码实现,具体是自己是进入一个不需要登录的页面还是自动登录进入消息页面那就自己实现了。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // [2-EXT]: 获取启动时收到的APN NSDictionary* message = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; FLDDLogVerbose(@"didFinishLaunchingWithOptions message:%@", message); if (message) { NSString *payloadMsg = [message objectForKey:@"payload"]; NSString *record = [NSString stringWithFormat:@"[APN]%@, %@", [NSDate date], payloadMsg]; //如何跳转页面自己添加代码 // // self.window.rootViewController = self.viewController; } return YES; }
四:应用在线,系统栏不显示推送的消息。若想显示也可以,就是把需要显示的标题和内容放在body的键值对里,收到透传消息,弹出本地消息。弹出本地消息的代码如下,注意,一般要把重复间隔设置为0,不然你的应用每天这个时间就会显示通知,当然你有像这样的需求是个例外:
UILocalNotification *notification = [[UILocalNotification alloc] init]; if (notification != nil) { // 设置推送时间 notification.fireDate = [NSDate date]; // 设置时区 notification.timeZone = [NSTimeZone defaultTimeZone]; // 设置重复间隔 notification.repeatInterval = 0; // 推送声音 // notification.soundName = UILocalNotificationDefaultSoundName; // NSArray *array=[NSArray arrayWithObjects:@"order_music_texi.mp3",@"order_music_new.mp3",@"order_music_comfortable.mp3",@"order_music_luxury.mp3",@"order_music_commicail.mp3", nil]; NSArray *arrayBody=[NSArray arrayWithObjects:@"您有一个出租车订单",@"您有一个新能源订单",@"您有一个舒适型订单",@"您有一个豪华型订单",@"您有一个商务型订单", nil]; // notification.soundName = array[[[newDict valueForKey:@"serviceType"] intValue] - 1]; // // 推送内容 notification.alertBody = arrayBody[[[newDict valueForKey:@"serviceType"] intValue] - 1]; //显示在icon上的红色圈中的数子 notification.applicationIconBadgeNumber =0; //添加推送到UIApplication UIApplication *app = [UIApplication sharedApplication]; [app scheduleLocalNotification:notification]; }
个推测试网站,发送iOS透传消息时,可以选择特定用户,需要上传CID列表。个推开放平台上特定用户推送时上传的用户列表是怎样的格式是:上传的是txt文件,一行一个clientid,回车换行。具体见这个例子,你把里面那行clientid换成自己的就可以,注意:要保持纯文本格式,保留换行符。个推cid列表文件