美文网首页iOS
iOS推送Tips

iOS推送Tips

作者: 和谐共处 | 来源:发表于2017-06-16 15:33 被阅读1次

清除通知栏所有通知

//只要设置角标不相同时,再设置为0就可以清除
[UIApplication sharedApplication].applicationIconBadgeNumber = 1;
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;

推送通知进入后台处理通知消息

1.后台推送消息设置,要再推送消息中加入键值对"content-available" = 1。这种方式为静默推送
例如:

aps =     {
        alert = "一条新的消息";
        "content-available" = 1;
        sound = default;
    };

2.App端的需要远程通知后台模式,在plist添加如下key

<key>UIBackgroundModes</key>
<array>
    <string>fetch</string>
    <string>remote-notification</string>
</array>

消息处理在如下方法回调中
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:
(void (^)(UIBackgroundFetchResult))completionHandler {
NSLog(@"收到推送通知:%@", userInfo);
completionHandler(UIBackgroundFetchResultNewData);
}

相关文章

网友评论

    本文标题:iOS推送Tips

    本文链接:https://www.haomeiwen.com/subject/qzhmqxtx.html