IOS收到推送消息后,不调用APNs通知回调方法


(翎小伊) #1

app相关代码

AppDelegate.m

@interface AppDelegate ()<JPUSHRegisterDelegate>

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  ...
  //初始化APNS
  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];
  //极光推送
  [JPUSHService setupWithOption:launchOptions appKey:@"xxxxxxxx"
                        channel:@"AppStore"
               apsForProduction:0 //1代表生产环境  0代表开发环境
          advertisingIdentifier:nil];
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
  /// Required - 注册 DeviceToken
  [JPUSHService registerDeviceToken:deviceToken];
  
//  [[NIMSDK sharedSDK] updateApnsToken:deviceToken];

}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
  NSLog(@"fail to get apns token :%@",error);
}

#pragma mark- JPUSHRegisterDelegate

// iOS 10 Support
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
  // Required
  NSDictionary * userInfo = notification.request.content.userInfo;
  NSLog(@"------------------444444");
  if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
    
    
    [[UserRecordUtils shared] savePushInfoWithInfo:userInfo.yy_modelToJSONString];
    [JPUSHService handleRemoteNotification:userInfo];
  }
  completionHandler(UNNotificationPresentationOptionAlert|UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound); // 需要执行这个方法,选择是否提醒用户,有Badge、Sound、Alert三种类型可以选择设置
}

// iOS 10 Support
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
  // Required
  NSDictionary * userInfo = response.notification.request.content.userInfo;
  NSLog(@"------------------333333");
  if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
    [JPUSHService handleRemoteNotification:userInfo];
  }
  completionHandler();  // 系统要求执行这个方法
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
  NSLog(@"------------------111111");
  // Required, iOS 7 Support
  [JPUSHService handleRemoteNotification:userInfo];
  completionHandler(UIBackgroundFetchResultNewData);
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
  NSLog(@"------------------222222");
  // Required,For systems with less than or equal to iOS6
  [JPUSHService handleRemoteNotification:userInfo];
}

AppDelegate.h

@interface AppDelegate : UIResponder <UIApplicationDelegate> 

@property (nonatomic, strong) UIWindow *window;

@end

出现问题

  • 这段代码初始化后,能收到极光的推送消息
  • 但是无论是收到消息,还是通过消息点击,都不会再后台打印预期的:----------------xxxxxx

操作步骤

  • 直接在xcode选择真机 -> RUN -> (iphone运行后) -> 按Home键让app进入后台 -> 到极光官网进行推送 -> 推送成功收到消息 -> 点击消息,在xcode控制台收不到打印日志

#2

点击消息走


获取消息内容:

点击没走代码方法,那走了什么呢?日志里面有什么信息呢?


(翎小伊) #3

另外初始化成功后 日志并没有打印 类似SDK中说初始化成功会收到的消息内容

2016-08-19 17:12:12.745823 219b28[1443:286814]  | JPUSH | I - [JPUSHLogin] 
----- login result -----  
uid:5460310207   
registrationID:171976fa8a8620a14a4  

不知道是否和这个有关系

但是通过极光服务器进行推送(我使用别名进行推送的),iphone确实能收到消息


(翎小伊) #4

无论是收到消息 还是点击消息 日志中都木有收到任何提示


#5

那是不是你并没有开启日志调试或者屏蔽了日志呢?


(翎小伊) #6

收到~ 日志一直走的默认设置
我按照您的方法试试看 看是否是因为尚未开启

- (void)applicationWillEnterForeground:(UIApplication *)application {
  
  NSLog(@"上传登录信息到服务端")
}

可是App从后台进入前台的时候 可以收到 上传登录信息到服务端 这条日志记录


(翎小伊) #7

打开日志 可用了~ 谢谢~ @Lris


#8

好的~不客气。