iOS推送通知自定义格式

我是所有iOS推送通知域的新手。 我已经尝试使用下面的代码的基本推送通知,它完美的作品。 我正在使用“使用JdSoft.Apple.Apns.Notifications;” 完成这个。 代码如下:

Notification alertNotification = new Notification(testDeviceToken); alertNotification.Payload.Alert.Body = "Hello World"; alertNotification.Payload.Sound = "default"; alertNotification.Payload.Badge = 1; 

这给以下结构的iPhone输出:

 { aps = { alert = "Hello World"; badge = 1; sound = default; }; } 

我现在有要求添加自定义标签,如下所示:

 {  "aps":   {    "alert": "Hello World",    "sound": "default", "Person":     {      "Address": "this is a test address",      "Name": "First Name",      "Number": "023232323233"   } } } 

我发现很难在“aps”中获得“Person”。 我也知道你可以使用下面的代码添加一个自定义属性:

alertNotification.Payload.AddCustom(“Person”,Newtonsoft.Json.JsonConvert.SerializeObject(stat));

但是上面的代码并没有添加“aps”标签。 请告诉我如何实现?

您不能将自定义标签放在aps标签中。 以下是文件所述的内容:

提供者可以在Apple保留的aps名称空间外指定自定义有效负载值。 自定义值必须使用JSON结构化和基本types:字典(对象),数组,string,数字和布尔值。

所以在你的情况下,你应该做一些事情:

 { "aps": { "alert": "Hello World", "sound": "default" }, "Person": { "Address": "this is a test address", "Name": "First Name", "Number": "023232323233" } } 

因此,您可以在主JSON中查找自定义有效内容,而不是在“aps”中:

 NSLog(@"%@",notification['Person']['Address']); 

以上将输出:

这是一个testing地址

您可以在Apple文档中find更多关于自定义有效载荷的示例。

问候,HrisTo