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会发送此保存的信息。

Service-to-device connection trust

remote server和APNS之间的交互

Token trust

整个工作流程,关键你还是要找到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之外

1.didreceiveremotenotification

    NSDictionary *obj=[userInfoobjectForKey:@"aps"];

    NSLog(@"%@",obj);

   NSLog(@"%@", [objobjectForKey:@"mydata"]);//alert ==null

2.launchoption

 if([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不对,但客户端获取到的内容是对的。。。。