【发布时间】:2026-02-15 09:35:01
【问题描述】:
解决方法在下面作为答案发布,我得出的结论是这是一个 iOS 8-8.1+ 错误,据我所知尚未修复。
原帖:
我不知所措,这之前可以工作,但在对我的应用程序进行多次更改和更新后它不再工作,我不能 100% 确定这是由于 iOS 8 还是我的应用程序,因为这个应用程序已经很长一段时间的 WIP。
如果我(用户)想要允许来自我的应用的通知,我不会收到提示。
更新:我在另一台设备(iPhone 5、iOS 8.1.2)上测试了我的应用程序并成功请求许可,但它仍然无法在我的设备(iPhone 6+、iOS 8.0)上运行。
(为清楚起见进行编辑:该测试是该应用程序在 iPhone 5、iOS 8.1.2 上的首次安装,并且如更新 2 所述,在 iPhone 5 上重新安装时问题仍然存在。)
更新 2:当我从第二台设备(更新 1:iPhone 5)卸载该应用程序时,它再也没有提示我获得通知权限,但它仍然有效,并且日志还显示设置的权限。但它仍然提示用户提供位置权限。
错误:
2014-12-17 09:49:51.852 Attempting to schedule a local notification <UIConcreteLocalNotification: 0x170344620>{fire date = (null), time zone = (null), repeat interval = 0, repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = Wednesday, December 17, 2014 at 9:49:51 AM Central Standard Time, user info = (null)} with an alert but haven't received permission from the user to display alerts
2014-12-17 09:49:51.853 Attempting to schedule a local notification <UIConcreteLocalNotification: 0x170344620>{fire date = (null), time zone = (null), repeat interval = 0, repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = Wednesday, December 17, 2014 at 9:49:51 AM Central Standard Time, user info = (null)} with a sound but haven't received permission from the user to play sounds
我以前可以正常工作的代码:
AppDelegate : didFinishLaunchingWithOptions
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}
我已经尝试过的代码:
if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
}
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
&
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}
&
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge
|UIRemoteNotificationTypeSound|UIRemoteNotificationTypeAlert) categories:nil];
[application registerUserNotificationSettings:settings];
NSLog(@"current notifications : %@", [application currentUserNotificationSettings]);
[application registerForRemoteNotifications];
}
else
{
[application registerForRemoteNotificationTypes:
(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}
我已经在 AppDelegate : didFinishLaunchingWithOptions 和 IBAction 上的 FirstViewController 中单独和一起尝试了所有这些(当然用 [UIApplication sharedApplication] 替换应用程序)
在我尝试设置权限后,我尝试签入 NSLog:
NSLog(@"current notifications : %@", [[UIApplication sharedApplication] currentUserNotificationSettings]);
NSLog:
current notifications : <UIUserNotificationSettings: 0x170435ee0; types: (none);>
在我的应用程序中,我请求允许使用他们的位置就好了,并尝试在询问他们的位置之前和之后请求通知权限,但这没有任何区别。
位置许可代码可以正常工作..
self.locationManager = [[CLLocationManager alloc] init];
if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[self.locationManager requestAlwaysAuthorization];
}
【问题讨论】:
-
听起来你的意思是这是 iOS 8 中的一个错误,在 iOS 8.1 中已修复。这就是它不起作用的地方和它起作用的地方之间的区别,对吧?
-
我不认为这是权限工作与否之间的错误,而是用户安装应用后提示权限未清除的提示。基本上使它永久用于应用程序。
-
没错。但在 iOS 8.1 中这是固定的吗?
-
不,不是。在任何 iOS 8(8.0 或 8.1)上,用户删除并重新安装应用程序后,它都不会提示通知权限。
-
当开发人员允许应用程序在他们的第一次测试中获得通知时可能会被忽视,除非它完全是一个新设备,否则他们将永远不会再次收到提示,所以在我的情况下,我必须说不允许一开始的通知,现在我无法重新提示。
标签: ios objective-c uilocalnotification