【问题标题】:iOS: Is there a way to know if user has opted out of notifications?iOS:有没有办法知道用户是否选择退出通知?
【发布时间】:2014-11-13 18:57:32
【问题描述】:

通过CLAuthorizationStatus,我可以确切地知道用户是否拒绝了应用程序权限(kCLAuthorizationStatusDenied)或者状态是否未确定(kCLAuthorizationStatusNotDetermined)。

... 那么通知服务有类似的东西吗?我似乎找不到任何东西,似乎没有办法区分拒绝权限的用户和尚未显示权限弹出窗口的用户。

【问题讨论】:

  • 遇到同样的问题。 [[UIApplication sharedApplication] currentUserNotificationSettings] 在新安装应用程序时返回 0 或无。无法区分“尚未提示”或“拒绝”

标签: ios permissions push-notification apple-push-notifications


【解决方案1】:
UIUserNotificationSettings *currentSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];

此代码将提供与通知相关的最新设置。

【讨论】:

  • 这段代码无法区分用户还没有被提示和被提示拒绝的情况。所以它没有回答这个问题。
【解决方案2】:
if ([[[UIDevice currentDevice]systemVersion]floatValue] >= 8.0) {
    UIUserNotificationSettings *current = [[UIApplication   sharedApplication]currentUserNotificationSettings];
    if (current.types != UIUserNotificationTypeNone){
        NSLog(@"Notifications Enabled ios 8");
    } else {
        NSLog(@"Notifications not Enabled ios 8");
    }

} else {
    UIRemoteNotificationType types = [[UIApplication sharedApplication]enabledRemoteNotificationTypes];
    if (types != UIRemoteNotificationTypeNone)
    {
        NSLog(@"Notifications Enabled");
    }
    else
    {
        NSLog(@"Notifications not Enabled");
    }
}

【讨论】:

  • 这段代码无法区分用户还没有被提示和被提示拒绝的情况。所以它没有回答这个问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-10-31
  • 1970-01-01
  • 2017-05-10
  • 2023-03-18
  • 1970-01-01
  • 1970-01-01
  • 2014-09-11
相关资源
最近更新 更多