iOS

iOS推送Tips

2017-06-16  本文已影响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);
}

上一篇下一篇

猜你喜欢

热点阅读