iOS silent push should update application badge count

社会主义新天地 提交于 2019-12-18 09:22:51

问题


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.

Is it possible?

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

来源:https://stackoverflow.com/questions/48581495/ios-silent-push-should-update-application-badge-count

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!