極光配置都OK了,推送能力打開了,Apple的推送證書也配置了,極光后臺的推送證書也驗證成功了,推送也打印了logo.
----- login result -----
uid:6271995743
registrationID:191e35f7e040c807e00
但是仍然收不到推送!!!!
通過一番騷操作及測試之后,發(fā)現(xiàn)是未實現(xiàn)JPUSHRegisterDelegate的兩個代理方法
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler ;//即將顯示推送
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler ;//收到推送
下面是代理的實現(xiàn),可以復制粘貼使用
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
NSDictionary * userInfo = notification.request.content.userInfo;
UNNotificationRequest *request = notification.request; // 收到推送的請求
UNNotificationContent *content = request.content; // 收到推送的消息內容
NSNumber *badge = content.badge; // 推送消息的角標
NSString *body = content.body; // 推送消息體
UNNotificationSound *sound = content.sound; // 推送消息的聲音
NSString *subtitle = content.subtitle; // 推送消息的副標題
NSString *title = content.title; // 推送消息的標題
if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
[JPUSHService handleRemoteNotification:userInfo];
NSLog(@"iOS10 前臺收到遠程通知:%@", userInfo);
}
else {
// 判斷為本地通知
NSLog(@"iOS10 前臺收到本地通知:{\nbody:%@万矾,\ntitle:%@,\nsubtitle:%@,\nbadge:%@朽缴,\nsound:%@,\nuserInfo:%@\n}",body,title,subtitle,badge,sound,userInfo);
}
completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert); // 需要執(zhí)行這個方法叮盘,選擇是否提醒用戶棚贾,有Badge鹰服、Sound、Alert三種類型可以設置
}
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
NSDictionary * userInfo = response.notification.request.content.userInfo;
UNNotificationRequest *request = response.notification.request; // 收到推送的請求
UNNotificationContent *content = request.content; // 收到推送的消息內容
NSNumber *badge = content.badge; // 推送消息的角標
NSString *body = content.body; // 推送消息體
UNNotificationSound *sound = content.sound; // 推送消息的聲音
NSString *subtitle = content.subtitle; // 推送消息的副標題
NSString *title = content.title; // 推送消息的標題
if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
[JPUSHService handleRemoteNotification:userInfo];
NSLog(@"iOS10 收到遠程通知:%@",userInfo);
}
else {
// 判斷為本地通知
NSLog(@"iOS10 收到本地通知:{\nbody:%@勤讽,\ntitle:%@,\nsubtitle:%@,\nbadge:%@厢漩,\nsound:%@膜眠,\nuserInfo:%@\n}",body,title,subtitle,badge,sound,userInfo);
}
completionHandler(); // 系統(tǒng)要求執(zhí)行這個方法
}
主要體現(xiàn)在completionHandler(); 這個方法要手動調用執(zhí)行
否則是收不到推送的.
希望碰到這個問題的小伙伴盡早看到這篇文章,早日脫離苦海 = =
good luck!