如何处理用户选择的通知设置权限警报

时间:2017-02-12 18:31:55

标签: ios notifications alert uilocalnotification

在某些视图控制器中,我弹出此通知设置消息:

  

My app希望向您发送通知,其中可能包含提醒,声音和图标徽章。这些可以在设置

中配置

如何处理短信的Don't AllowAllow按钮?

如果用户点击Allow,我需要更改同一视图控制器中的标签文字。

2 个答案:

答案 0 :(得分:1)

我假设您应用中的某个地方有这样的代码:

UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:... categories:...];
[application registerUserNotificationSettings:settings];

完成此操作后,系统将显示您正在讲话的提示。在那一刻,应用将收到UIApplicationWillResignActiveNotification(您可以在应用代表或NSNotificationCenter注册)。然后,在用户做出一些选择之后,系统将发送UIApplicationDidBecomeActiveNotification(也在app委托或通知中)。此时,使用以下代码检查权限:

UIUserNotificationSettings *settings = application.currentUserNotificationSettings;
if (settings.types & UIUserNotificationTypeSound & UIUserNotificationTypeBadge) {
    // sound and icon badge allowed
}
else {
    // either sound or icon badge or both disallowed
}

答案 1 :(得分:1)

以下答案解决了这个问题。

当系统级弹出消息可见时,applcation将调用resignActivity。当您点击"允许" "不允许" 提醒按钮时,您的提醒消息将被解除,它将在AppDelegate课程中调用- (void)applicationDidBecomeActive:(UIApplication *)application { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. dispatch_async(dispatch_get_main_queue(), ^{ [[NSNotificationCenter defaultCenter] postNotificationName:@"NOTIFICATION_KEY" object:self]; }); } ,而在NSNotificationCenter注册时,可以在用户立即更改文本。

 this.AuthService.loginAuth(this.data).subscribe(function(response) {
  console.log("Success Response" + response)
},
  function(error) {
  console.log("Error happened" + error)
},
  function() {
  console.log("the subscription is completed")
});
相关问题