ano*_*erd 4 objective-c ios swift
我不确定这是否是一个奇怪的错误,但在我的
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
我有以下几行代码来请求用户权限:
// Register for Push Notitications, if running iOS 8
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
} else {
// Register for Push Notifications before iOS 8
[application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound)];
}
Run Code Online (Sandbox Code Playgroud)
在模拟器上,一切正常,但在我的 iPhone 上,当我安装应用程序时,它不会要求这些权限。我已经启动了断点以确保行执行并且它们执行。
当我进入Settings > Notifications > My App通知时,系统似乎知道我之前已授予权限,因此它不会询问,但这似乎很奇怪。
有没有人见过这个?
居然再次谷歌搜索后找到了答案(之前没找到答案)
直接来自苹果:
在 iOS 上重置推送通知权限警报 启用推送的应用程序首次注册推送通知时,iOS 会询问用户是否希望接收该应用程序的通知。一旦用户对此警报做出响应,除非设备恢复或应用程序已卸载至少一天,否则它不会再次出现。
如果您想模拟应用程序的首次运行,您可以将应用程序卸载一天。您可以按照以下步骤实现后者,而无需等待一天:
- 从设备中删除您的应用程序。
- 完全关闭设备并重新打开。
- 前往“设置”>“通用”>“日期与时间”,然后将日期提前一天或更长时间。
- 再次完全关闭设备并重新打开。
这样做后,请求许可再次起作用。
| 归档时间: |
|
| 查看次数: |
1469 次 |
| 最近记录: |