简体   繁体   English

iOS中的自定义推送通知

[英]Custom push notification in iOS

I am from Android background, now working in cross platform mobile application. 我来自Android背景,目前在跨平台移动应用程序中工作。 I don't have any knowledge in iOS. 我对iOS没有任何了解。 In my application, I need to customize the push notification in displayed in the notification bar. 在我的应用程序中,我需要自定义通知栏中显示的推送通知。 In Android I achieve this. 在Android中,我实现了这一点。 Can any one help me in iOS? 有人可以在iOS中为我提供帮助吗?

This is my json data : 这是我的json数据:

{
"Test1":"Value 1",
"Test2":"Problem:[{"a":"b"},{"c":"d"}]"
}

Output should be : Value 1 --> b ,d 输出应为:值1-> b,d

What I have tried 我尝试过的

- (void)handleBackgroundNotification:(NSDictionary *)notification
{
     NSMutableString *alert = [NSMutableString stringWithString:@""];
    if ([notification objectForKey:@"Test1"]){
        [alert appendString:(NSString *)[notification objectForKey:@"Test1"]];
    }
}

I dont know if this is correct. 我不知道这是否正确。

You are sending Apple Push Notifications from your server to an iOS application. 您正在将Apple Push Notifications从您的服务器发送到iOS应用程序。 Apple Push Notifications offer much less freedom than Android's GCM. 与Android的GCM相比,Apple Push Notifications提供的自由度要低得多。 The JSON you are sending should look like this : 您发送的JSON应该如下所示:

{"aps":{"alert":"message","badge":3,"sound":"sound-file-name"},"custom-property":"custom-value"}

The only parameter used to display the notification is the "alert" parameter (there are some minor variations - the "alert" parameter can be a dictionary by itself and define some additional parameters used for displaying the message, but none of them is a custom parameter). 用于显示通知的唯一参数是“ alert”参数(有一些细微变化-“ alert”参数本身可以是字典,并定义了一些用于显示消息的附加参数,但它们都不是自定义的参数)。

You can add custom parameters, as shown above, but they will not be shown in the notification (they will be passed to the method that handles the notification if the user taps on the notification). 您可以添加自定义参数,如上所示,但它们不会显示在通知中(如果用户点击通知,它们将被传递给处理通知的方法)。 Unlike Android, you don't write the code that displays the notification. 与Android不同,您无需编写显示通知的代码。 In iOS it's part of the operating system. 在iOS中,它是操作系统的一部分。

You can further read about the notification payload here . 您可以在此处进一步了解通知有效内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM