gpt4 book ai didi

iOS 7 - 静默推送通知

转载 作者:行者123 更新时间:2023-11-29 10:41:01 25 4
gpt4 key购买 nike

我设置了静默推送通知,当应用程序在前台或后台运行时一切正常。

问题是当应用程序未激活/终止时(如果我理解得很好,任何应用程序在后台运行 30 秒后都会自动终止)。

我的payload是这样的

{"aps":{"alert":"test","sound":"bingbong.aiff","badge":33,"content-available":1}}

一切正常,但当我收到此推送时,角标(Badge)图标未更新(应用程序图标附近没有出现 33)。这是第一个问题。

第二个问题是我不知道如何在应用程序被杀死时得到通知。

我的想法是在角标(Badge)图标大于 1 时调用该服务,这样我就知道有一些通知要下载,我可以联系服务器获取它们。

最佳答案

静默推送通知不需要警报,也不需要指定声音,因为它不会呈现给用户。

您将通过 application:didReceiveRemoteNotification:fetchCompletionHandler::获得静默通知

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
//load the new available content and call the completionhandler.
}

如果应用程序具有正确的权限,则应显示角标(Badge)。您可以像这样注册您的应用以显示角标(Badge):

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge];

无论如何,您无需检查角标(Badge)编号即可下载新内容。您可以简单地将自己的键值对附加到通知中:

{
"aps": {
"badge": 33,
"content-available":1
},
"load-data": 1,
"load-data-id": 12
}

当您在应用程序中收到通知时,只需在 userInfo 字典中检查您的参数:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
int loadData = [[userInfo objectForKey:@"load-data"] intValue];
int loadDataId = [[userInfo objectForKey:@"load-data-id"] intValue];
}

所有这些都记录在 Local and Push Notification Programming Guide 中在 iOS 文档中。

关于iOS 7 - 静默推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24539048/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com