notification相关二
来源:互联网 发布:淘宝网店标志图片 编辑:程序博客网 时间:2024/06/13 09:11
比较本地消息和远程消息的差别:
1. 一个来自系统自身;一个来自外部,apns
2. 一个是通过UIlocalNotification类似计划任务一样,规定了消息的格式,显示时间等;一个是通过主动注册
当设备和程序没有变化时,devicetoken是不会变的/
3. 多有payload的概念,local notification object/remote-notification payload.
4. 当注明app接受注册接受notification,就和apns建立一条有效持久的通道
5. 发送的内容以二进制格式,apns有sandbox和产品环境,
6. knowledge of TLS/SSL and streaming sockets is helpful
7. 两个的作用和表现形式是一样的
8. notification alert的样式中包含两个按钮,一个close,一个view(应该是可以改名字的),app是可以自定义右边那个action按钮的文字的
尽管你这里可以自己定义 payload中的属性/值,但无论如何不能依靠remot pushnotification作为数据传输
的方式。
APNS会保存最新的一条notification,如果手机/pad设备一致没有online,比如没有芯片/开机/网络
,等到建立通道,apns会发送此保存的信息。
remote server和APNS之间的交互
整个工作流程,关键你还是要找到id-token,然后知道发送内容到那个token,然后是payload。
定制化payload
{
"aps" : { "alert" :"This is the alert text", "badge" : 1, "sound" :"default" },
"server" : { "serverId" :1, "name" : "Server name")
}
举个例子来说,custom数据可以是对话id/也可以是时间戳表示服务器端发送消息的时间/
任何与提示消息关联的action,不应该是指令性质的,例如删除数据/
如何使你看到的提示信息更完善(合理绕过256字符限制):
充分利用了我们的本地资源文件,loc-key,他可以自动去本地的lproj寻找数据。。。。显示很长很长的多可以哦
To make this clearer, let’s consider an example. The provider specifies the following dictionary as the value of the alert property:
"alert" : { "loc-key" : "GAME_PLAY_REQUEST_FORMAT", "loc-args" : [ "Jenna", "Frank"] },
When the device receives the notification, it uses "GAME_PLAY_REQUEST_FORMAT"
as a key to look up the associated string value in the Localizable.strings
file in the .lproj
directory for the current language. Assuming the current localization has an Localizable.strings
entry such as this:
"GAME_PLAY_REQUEST_FORMAT" = "%@ and %@ have invited you to play Monopoly";
the device displays an alert with the message “Jenna and Frank have invited you to play Monopoly”.
如何获取自己的属性/值// Create the payload body
$body['aps'] = array(
'alert' => $message,
'sound' => 'default',
'mydata' => 'test data'
);
//$body 如何增加自定义,在aps之外
NSDictionary *obj=[userInfoobjectForKey:@"aps"];
NSLog(@"%@",obj);
NSLog(@"%@", [objobjectForKey:@"mydata"]);//alert ==null
2.launchoptionif([launchOptionsobjectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) {
//a dictionary representing the payload of the remote notification.
//if we're here, apps was launched due to Remote Notification
NSDictionary *obj=[launchOptionsobjectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
NSLog(@"%@", [[objobjectForKey:@"aps"]objectForKey:@"mydata"]);
虽然你做出了以上处理,但由于notification在apns会被后期的命令覆盖,删除指令会被后期的覆盖(如果在这段时间没有开机/连线)
Example 4. The interesting thing about the payload in this example is that it uses the loc-key
and loc-args
child properties of the alert
dictionary to fetch a formatted localized string from the application’s bundle and substitute the variable string values (loc-args
) in the appropriate places. It also specifies a custom sound and include a custom property.
{
"aps" : {
"alert" : { "loc-key" : "GAME_PLAY_REQUEST_FORMAT", "loc-args" : [ "Jenna", "Frank"] },
"sound" : "chime",
},
"acme" : "foo"
}
这个测试没有成功,可能是format不对,但客户端获取到的内容是对的。。。。
- notification相关二
- Notification(二)
- Notification二
- notification 修改相关文件
- Notification集合(二)
- Remote Notification (二)
- Notification详解(二)
- Android(二):Notification基本操作
- JMX学习笔记(二)-Notification
- Android Notification 基础 (二)
- JMX学习笔记(二)-Notification
- Notification的使用(二)
- 如何使用Notification的相关Style实现不同类型的Notification
- Apple Push Notification Service(APNS)相关
- Notification 通知栏定义和相关问题
- Notification相关和一些关键点收集
- Notification和NotificationManager的使用(二)
- Notification和NotificationManager的使用(二)
- Assistance Required
- 第十二周实验报告2
- ICESSL使用备忘
- 程序员面试题精选100题(15)-含有指针成员的类的拷贝[C/C++/C#]
- 今天的工作增强
- notification相关二
- poj 1753 Flip Game 二进制状态压缩
- 用WinInet API实现ftp文件上传
- 线性表基础知识(四)
- 3D 学习笔记 几何混合 Geometry Blending
- 黑马程序员_分支结构与循环结构以及跳转语句
- Doubly connected edge list
- centos6.2使用yum安装lamp
- 开始找工作了。。。