简体   繁体   English

iPhone推送通知信息

[英]iPhone push notifications information

Is it possible to transfer any information in the push notification beside "badge" "sound" and "text" ? 是否可以在"badge" "sound""text"旁边的推送通知中传输任何信息?

For example, in the app "whatsapp" when a push notification appears and pressed, the app is opened but not going to the conversation. 例如,在应用程序"whatsapp"出现并按下推送通知时,应用程序将打开但不会进入对话。 My guess is that it can't know what conversation to go to. 我的猜测是它无法知道要进行什么对话。 But then I saw that in facebook messenger app it actually goes in the conversation. 但后来我在facebook messenger应用程序中看到它实际上是在谈话中。 how does the messenger app know that what conversation to go to? 信使应用程序如何知道要进行哪些对话?

Also, if it is possible to transfer information, why is it that apps like whatsapp don't use it and also ask you for your name so it will be displayed in the push? 此外,如果可以传输信息,为什么像whatsapp这样的应用程序不会使用它,并且还会询问您的姓名,以便它会在推送中显示?

Yes, indeed. 确实是的。 But your message size (in bytes) must not pass a certain threshold Apple has imposed. 但是,您的邮件大小(以字节为单位)不得超过Apple规定的某个阈值。 You can then pull that info in the - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions using something like this: 然后,您可以使用以下内容在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions提取该信息:

NSDictionary* dictionary = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];

Where dictionary contains your push notification info. 字典包含推送通知信息。

There are apps that have permission to run in the background and other apps that have not. 有些应用程序有权在后台运行,而其他应用程序则没有。 May be facebook messenger app have this permission and can receive push notifications and do whatever is needed to go to the correct conversation or user. 可能是facebook messenger应用程序具有此权限,可以接收推送通知并执行任何操作以转到正确的对话或用户。 I don't know if this is true but it could be a possible reason. 我不知道这是否属实,但可能是一个可能的原因。

in this method we can display pushnotifications alerts and their action according to our app 在这种方法中,我们可以根据我们的应用程序显示推送警报及其操作

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo   
{


    NSLog(@"did receive remore notification %@",userInfo);
    if(isForground)
    {
    }
}

You should take a look at this documentation section Examples of JSON Payloads 您应该查看本文档部分JSON Payloads的示例

At the bottom you can see custom payload examples like: 在底部,您可以看到自定义有效负载示例,如:

{
    "aps" : {
        "alert" : "You got your emails.",
        "badge" : 9,
        "sound" : "bingbong.aiff"
    },
    "acme1" : "bar",
    "acme2" : 42
}

Where acme1 and acme2 are custom data that you can pass to the push notification and get it inside you app after launched. 其中acme1acme2是自定义数据,您可以将其传递给推送通知并在启动后将其放入应用程序内部。

The data is available through UIApplicationDelegate callbacks as described here Handling Local and Remote Notifications 数据可通过UIApplicationDelegate回调获得,如此处所述处理本地和远程通知

You can add more arguments in your payload. 您可以在有效负载中添加更多参数。 In our app we add something like groupID, or type. 在我们的应用中,我们添加了类似groupID或类型的内容。 See this stack overflow for adding more payload arguments 查看此堆栈溢出以添加更多有效负载参数

APNS JSON PAYLOAD - more arguments APNS JSON PAYLOAD - 更多参数

确保消息大小不超过256个字节。这是有效负载的阈值限制

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

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