iOS推送Tips
阿新 • • 發佈:2021-05-28
清除通知欄所有通知
//只要設定角標不相同時,再設定為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); }
轉載於:https://my.oschina.net/hehuiqi/blog/1591202