极光推送的坑
極光推送開發環境可以收到,生產環境收不到推送
初次發現這個問題的時候 首先排查的就是證書配置。
綠色的表示沒什么問題。
開發環境的證書跟生產環境的證書 都已經配置完成,
下面我們看看極光官網的配置
這個也沒有問題。 然后看代碼
//極光植入
? ? [JPUSHService setBadge:0]; //JPush服務器角標置為0
? ? [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];//app角標置為0
? ? //極光推送
? ? //notice: 3.0.0及以后版本注冊可以這樣寫,也可以繼續用之前的注冊方式
? ? JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
? ? entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound;
? ? if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
? ? ? ? // 可以添加自定義categories
? ? ? ? // NSSet<UNNotificationCategory *> *categories for iOS10 or later
? ? ? ? // NSSet<UIUserNotificationCategory *> *categories for iOS8 and iOS9
? ? }
? ? [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
?? ?
? ? //JAppKey : 極光推送申請下來的appKey Jchannel : 可以直接設置默認值即可 Publish channel
? ? //是否是開啟的
? ? BOOL JPush = NO;
? ? if ([kMemberLoginProductFlag isEqualToString:@"YES"])
? ? {
? ? ? ? JPush = YES;
? ? }
? ? else{
? ? ? ? JPush = NO;
? ? }
?? ?
? ? [JPUSHService setupWithOption:launchOptions appKey:JiGuangAppKey
? ? ? ? ? ? ? ? ? ? ? ? ? channel:nil apsForProduction:JPush]; //如果是生產環境應該設置為YES
?
#pragma mark - 向服務器上報Device Token? ? 極光代理
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
?? ?
? ? // Required - 注冊 DeviceToken
?? ?
? ? [JPUSHService registerDeviceToken:deviceToken];
?? ?
}
#pragma mark - 極光推送代理
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
?? ?
? ? NSDictionary * userInfo = notification.request.content.userInfo;
? ? DLog(@"@@@@@@@進來了進來了? %@",userInfo);
? ? if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]])? {
? ? ? ? [JPUSHService handleRemoteNotification:userInfo];
? ? }
? ? completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);? // 需要執行這個方法,選擇是否提醒用戶,有Badge、Sound、Alert三種類型可以選擇設置
}
?
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
?? ?
? ? NSDictionary * userInfo = response.notification.request.content.userInfo;
? ? DLog(@"@@@@@@@進來了進來了? %@",userInfo);
? ? if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
? ? ? ? [JPUSHService handleRemoteNotification:userInfo];
?? ? ? ?
? ? }
? ? completionHandler(); // 系統要求執行這個方法
? ? [JPUSHService setBadge:0]; //JPush服務器角標置為0
? ? [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];//app角標置為0
?? ?
? ? //這里是自定義了 。。。。。。
? ? if([UIApplication sharedApplication].applicationState == UIApplicationStateActive || [UIApplication sharedApplication].applicationState == UIApplicationStateBackground)
? ? {
? ? ? ? DLog(@"@@@@@@@進來了");
?? ? ? ?
? ? ? ? [self pushViewControllerWith:userInfo];
? ? }else
? ? {
?? ? ? ?
//? ? ? ? if (![USER_DEFAULT valueForKey:kNotificationPushDictionary])
//? ? ? ? {
//? ? ? ? ? ? [self pushViewControllerWith:userInfo];
//? ? ? ? }
? ? ? ? DLog(@"@@@@@@@進來了進來了");
? ? ? ? ? ? ? ? [self pushViewControllerWith:userInfo];
? ? }
}
代碼看了半天也沒啥問題。最后發現是打包的問題,測試環境直接打包就行。
但是生產的 必須一定要adhoc打包才能測試 其他方式打包安裝不行。坑啊 。
其次,前后臺所有的sdk版本要可以對的上的。版本不統一也可能出現推送收不到的問題。瞎忙了2天,快上線了,頭都大了。
總結
- 上一篇: 项目中遇到问题的解决方法合集
- 下一篇: cesium添加填充_Cesium中级教