iOS推送出了点问题,之前还好好的,而且上线过好几版了,最近测试说iOS好多用户收不到推送了,然后Debug发现:既不调用- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken方法,也不调用- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error 方法。之前在Xcode6上还好好的,升级到Xcode7之后就这两个方法都调用不进去了。然后再用Xcode6打开也同样调不进去了。升级到Xcode7之后,在适配iOS9的时候改过一些配置文件。
首先说明几点:
1,已经确保证书没问题,因为我新建了个测试工程,用同一个证书却可以调用- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken方法。并且原来的项目和新建的测试工程在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法中的代码是一模一样的。测试工程能回调- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken方法,但原项目不回调,也不调用- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error方法。
2,确定手机已经联网。
3,也有是否接受消息通知的弹窗,而且设置-通知里边确定是允许推送的。
补充,原项目和新建的测试工程在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法中的代码一模一样,如下:
-
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
#ifdef __IPHONE_8_0
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
} else {
UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];
}
#else
UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];
#endifreturn YES;
}
如有人遇到同样的问题,请帮忙解答,非常感谢!