带有发送自定义数据的 Apple 推送通知 [英] Apple Push Notification with Sending Custom Data

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

问题描述

我正在从 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 令牌是 Apple 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, 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 字节,当然,这包括您的自定义参数.因此,您可能不得不(冒着降低可读性的风险)调用您的自定义参数ji"而不是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.

所有这些都记录在 本地和推送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).

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

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