極光推送文檔:https://docs.jiguang.cn/jpush/client/iOS/ios_api/#apns
// 前臺收到推送消息,未點擊情況執行
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler;
// 點擊推送消息獲取信息
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler;
如果 App 狀態為未運行,此函數將被調用,如果launchOptions包含UIApplicationLaunchOptionsRemoteNotificationKey表示用戶點擊apn 通知導致app被啟動運行;如果不含有對應鍵值則表示 App 不是因點擊apn而被啟動,可能為直接點擊icon被啟動或其他。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
// apn 內容獲取:
NSDictionary *remoteNotification = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
}
設置Badge
value 取值范圍:[0,99999]
+ (BOOL)setBadge:(int)value
設置badge值,本地仍須調用UIApplication:setApplicationIconBadgeNumber函數
調用此 API 來設置別名,支持回調函數
+ (void)setTags:(NSSet *)tags
alias:(NSString *)alias
fetchCompletionHandle:(void (^)(int iResCode, NSSet *iTags, NSString *iAlias))completionHandler;
例: 如果移除別名,alisa可以傳空字符串
[JPUSHService setTags:nil alias:@"1" fetchCompletionHandle:^(int iResCode, NSSet *iTags, NSString *iAlias) {
if (iResCode == 0) {
//設置成功
}
}];