【问题标题】:iOS Local Notifications: app is not asking for permissions to notify the useriOS本地通知:应用程序不要求通知用户的权限
【发布时间】:2015-04-19 15:54:16
【问题描述】:

我不确定这是否是一个奇怪的错误,但在我的

- (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)];
    }

在模拟器上,一切正常,但在我的 iPhone 上,当我安装应用程序时,它不会要求这些权限。我已经启动了断点以确保这些行执行并且它们确实执行了。

当我进入Settings > Notifications > My App时,通知是开启的,所以系统似乎知道我之前已经授予了权限,所以它没有询问,但这似乎很奇怪。

有人见过吗?

【问题讨论】:

  • 您是否尝试从您的设备上卸载该应用程序并重新安装以重置所有内容?
  • 我假设stackoverflow.com/questions/12596165/… 也适用于此处:您必须重置隐私设置(或更改设备上的时间并按照评论中的说明重新启动)。

标签: ios objective-c swift


【解决方案1】:

我再次谷歌搜索后实际上找到了答案(我之前没有找到答案)

直接来自苹果:

在 iOS 上重置推送通知权限警报 当支持推送的应用注册推送通知时,iOS 会询问 用户是否希望接收该应用程序的通知。一旦用户 已对此警报做出响应,除非 设备已恢复或应用已卸载至少一天。

如果您想模拟您的应用的首次运行,您可以离开 该应用程序卸载了一天。您可以在没有的情况下实现后者 按照以下步骤实际等待一天:

  1. 从设备中删除您的应用程序。
  2. 完全关闭设备并 重新打开它。
  3. 进入设置 > 常规 > 日期和时间并设置 提前一天或更长时间约会。
  4. 再次完全关闭设备,然后 重新打开它。

完成此操作后,再次请求许可。

【讨论】:

  • “已被卸载至少一天”我想知道苹果曾经提出过什么扭曲的逻辑。删除应用程序应删除通知决定。感谢您的澄清
猜你喜欢
  • 1970-01-01
  • 2013-04-09
  • 1970-01-01
  • 2017-07-31
  • 2014-09-16
  • 1970-01-01
  • 2018-03-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多