我正在使用来自服务器的响应的UIlocal通知,当我在模拟器上运行应用程序时,它会在我发送给服务器的图像的通知区域显示通知,但是当您在真实设备上运行相同的应用程序时,它在我的通知区域中什么都不显示,代码很好,但我没有得到为什么它没有显示任何东西,请帮助我。 我的代码是,
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = res;
localNotification.alertBody = @"Image Sent";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
在我的AppDelegate.m文件中,它写成了这个,
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{
NSLog(@"User Info : %@",notification.request.content.userInfo);
completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);}
答案 0 :(得分:0)
在appdelegate中添加此方法,并从didfinishlaunchwithoption
调用它-(void)registerForLocalNotification{
if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings
settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|
UIUserNotificationTypeSound categories:nil]];
}
}