iOS推送Tips

清除通知栏所有通知

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

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

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

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

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

    UIBackgroundModes
    
        fetch
        remote-notification
    

消息处理在如下方法回调中

    - (void)application:(UIApplication *)application
        didReceiveRemoteNotification:(NSDictionary *)userInfo
              fetchCompletionHandler:
                  (void (^)(UIBackgroundFetchResult))completionHandler {
                  NSLog(@"收到推送通知:%@", userInfo);
      completionHandler(UIBackgroundFetchResultNewData);
    }

你可能感兴趣的:(iOS推送Tips)