【问题标题】:iOS 14 : UNUserNotificationCenter requestAuthorizationWithOptions always fails with "Notifications are not allowed for this application"iOS 14:UNUserNotificationCenter requestAuthorizationWithOptions 总是失败并显示“此应用程序不允许通知”
【发布时间】:2020-09-19 01:13:05
【问题描述】:

我找不到解决方案,对此感到目瞪口呆。我有这个代码:

UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert |
        UNAuthorizationOptionSound | UNAuthorizationOptionBadge;

[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions
        completionHandler:^(BOOL granted, NSError * _Nullable error) {
             NSLog(@"%i %@",granted, error);
        }];

然后它立即进入呼叫处理程序而不显示通知权限

2020-09-18 18:05:46.657991-0700 My App [404:9600] 0 Error Domain=UNErrorDomain Code=1 "Notifications are not allowed for this application" UserInfo={NSLocalizedDescription=Notifications are not allowed for this application}

我错过了什么?警报甚至没有弹出。

注意:同样的代码在 iOS 13.x 上没有问题,在 iOS 14 上它立即失败。

【问题讨论】:

    标签: ios notifications ios14 unusernotificationcenter


    【解决方案1】:

    我的问题是在产品名称部分使用土耳其语字符。

    https://developer.apple.com/forums/thread/660648

    在我的情况下,构建设置 - 包装 - 产品名称不是英文。改成英文就可以了。

    【讨论】:

      【解决方案2】:

      问题是你省略了一个步骤。在请求授权之前,调用getNotificationSettingsWithCompletionHandler: 并查看生成对象的authorizationStatus。如果是 UNAuthorizationStatusDenied,则没有必要继续。

      【讨论】:

      • 一开始没有要求通知。设备上全新安装,通知询问永远不会出现。系统设置甚至没有应用的通知设置。
      • 抱歉,需要明确的是,上面的代码是必需的,但在这种情况下,因为它是全新安装,所以没有实际意义
      【解决方案3】:

      我的产品名称是日语。当产品名称不是英文时,会发生上述问题!如果我将产品名称更改为英文就可以了!我已通过 Apple 反馈助手提出问题。

      【讨论】:

      • 有没有人弄清楚这一点。我有同样的问题。我的应用程序的名称是 mylittleworldapp,所以即使这不是一个外国名称,它也不一定是英文。将尝试解决方案,看看。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-17
      • 2021-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多