您是否注册了推送通知?
#define SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
if(SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(@"10.0")){
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
if( !error ){
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
}];
}
return YES;
}
您是否为以下委托方法实现了?
-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler{
//Called to let your app know which action was selected by the user for a given notification.
NSLog(@"Userinfo %@",response.notification.request.content.userInfo);
}
你能检查这个线程以获得更多线索吗
iOS 10 和 9 遵循不同的有效负载结构。
iOS 10 紧随其后
{
"aps":{
"alert":{
"body":"YOUR_MESSAGE."
},
"badge":1
},
“YOUR_VARIABLE” : "YOUR VALUE"
}
iOS < 9 如下
{
“aps” : {
“alert” : "YOUR_MESSAGE.”,
“badge” : 1,
“sound” : “default”
},
“YOUR_VARIABLE” : "YOUR VALUE"
}
我觉得这可能是问题