与发送自定义数据苹果推送通知 [英] Apple Push Notification with Sending Custom Data

查看:173
本文介绍了与发送自定义数据苹果推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从PHP求职申请发送推送通知到iPhone。我将关于新的就业机会推送通知。这是可能的,当用户点击的推送通知的观点弹出,然后用户重定向到设备的具体工作。

I am sending push notifications from php job application to iphone. I am sending push notifications regarding new jobs. Is this possible that when user click on the view of push notification pop up , then user redirect to the particular job in the device.

我的意思是我想知道我可以发送任何自定义数据与像的jobId,别的东西推送通知....让iPhone最终可以检索和显示特定的工作?

I mean I wanted to know can I send any custom data with push notification like jobId,something else....so that Iphone end Can retrieve and show the particular job ?

感谢。

推荐答案

无论您使用的语言和库时,推送通知的有效载荷是一个JSON有效载荷:

Regardless of the language and library you use, the push notification payload is a JSON payload:

{
    "aps": {
         "badge": 10,
         "alert": "Hello world!",
         "sound": "cat.caf"
    }
}

APS 标记是苹果APN数据。您可以自定义数据添加到您的有效载荷,以及:

The aps token is the Apple APN data. You can add custom data to your payload as well:

{
    "aps": {
         "badge": 10,
         "alert": "Hello world!",
         "sound": "cat.caf"
    },
    "job_id": 1
}

当您收到应用程序的通知只是检查通知您的字典参数:

When you receive the notification in the app just check for your param in the notification dictionary:

- (void)handleBackgroundNotification:(NSDictionary *)notification
{
    NSDictionary *aps = (NSDictionary *)[notification objectForKey:@"aps"];
    NSMutableString *alert = [NSMutableString stringWithString:@""];
    if ([aps objectForKey:@"alert"])
    {
        [alert appendString:(NSString *)[aps objectForKey:@"alert"]];
    }
    if ([notification objectForKey:@"job_id"])
    {
        // do something with job id
        int jobID = [[notification objectForKey:@"job_id"] intValue];
    }
}

请有效载荷的总规模为256的字节的,这包括,当然,你的自定义参数。所以,你可能要(减少可读性的风险)调用您的自定义参数吉,而不是JOB_ID挤字节。

Keep in mind that the total size of the payload is 256 bytes, and that includes, of course, your custom parameters. So you may have to (at risk of reducing readability) call your custom param "ji" instead of "job_id" to squeeze bytes.

所有这一切都在<一个被记录href=\"https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction.html\">Local和推送通知编程指南 iOS的文档中获得。肯定会推荐一读,因为它更复杂的比它最初的声音(至少,这就是我的想法)。

All of this is documented in the Local and Push Notification Programming Guide in the iOS documentation. Definitely would recommend a read because it's more complex than it initially sounds (at least, that's what I thought).

这篇关于与发送自定义数据苹果推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆