iOS静默推送应更新应用程序徽章计数 [英] iOS silent push should update application badge count

查看:161
本文介绍了iOS静默推送应更新应用程序徽章计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过接收静音推送来更新应用程序徽章计数。

Is it possible to update application badge count by receiving a silent push.

当应用程序未在后台运行时,不会调用此方法。
我的猜测是,即使应用程序没有在后台运行,也会调用此方法。我错了吗?

When the application is not running in the background, this method is not called. My guess is this method get called even if the app is not running in the background. Am I wrong?

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
        fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler
{
    int currentBadge = [UIApplication sharedApplication].applicationIconBadgeNumber;
    DLog(@"%@, badge = %i", userInfo, currentBadge);
    [UIApplication sharedApplication].applicationIconBadgeNumber = [UIApplication sharedApplication].applicationIconBadgeNumber + 1;
    completionHandler(UIBackgroundFetchResultNoData);
}

我只想通过收到的任何通知增加徽章编号。通知有效负载没有徽章字段。

I just want to increase badge number with any received notification. The notification payload do not have a "badge' field.

是否可以?

如果应用不运行后台,UIApplicationExitsOnSuspend = YES,我想知道在这种情况下是否会静音推送工作?

And if the app does not run background, UIApplicationExitsOnSuspend = YES, I wonder in this situation will silent push work or not?

推荐答案

有各种可能性用于预处理和修改iOS上通知的有效负载。

There are various possibilities for preprocessing and modify the payload of a notification on iOS.

iOS 10之前

您可以发送无声通知,不会向用户显示的内容。将在终止或在后台唤醒我们的应用程序,您将能够对通知内容进行预处理。查看更多信息这里,如何设置它。但是,此通知类型不是100%可靠,并且不应滥用,例如,用于所有要发送的通知,因为Apple可以停止在一些消息之后发送通知。

You could be sending Silent Notifications, what will not be not shown to the user. Will wake our application when it is terminated or in background, and you will be able to do preprocessing on the notification content. See more info here, how to set it up. However, this notification type is not 100% reliable, and should not be abused, e.g. used for all notifications to be delivered, because Apple could stop the notifications to be sent after a number of messages.

另一种选择是,如果您的应用程序支持 VoIP 。这样,您的应用程序几乎总是会听取推送通知,并且您将始终可以预先处理通知,然后再显示它们。但是,如果您的应用没有真正的 VoIP 功能,例如电话,Apple会在评论时拒绝您的应用。 这里是一个很棒的教程,如何设置。

The other option is, if your application supports VoIP. This way your app will pretty much always listen to push notifications, and you will be always available to preprocess the notifications, before you would be displaying them. However, if your app does not have real VoIP capabilities, e.g. phone calls, your app will be rejected by Apple on the review. Here is a great tutorial, how to set it up.

来自iOS 10

随着iOS 10的推出,我们终于可以进行预处理了甚至,当应用程序处于后台或终止时,我们的通知。无 VoIP 功能或需要发送的特殊通知类型。 此处是一个很棒的教程,如何设置。

With the introduction of iOS 10, we are finally able to do preprocessing on our notifications, even, when the app is in background or terminated. No VoIP capabilities or special type of notifications needed to be sent. Here is a great tutorial, how to set it up.

这篇关于iOS静默推送应更新应用程序徽章计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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