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

Ios 如何处理用户选择的通知设置权限警报,ios,notifications,alert,uilocalnotification,Ios,Notifications,Alert,Uilocalnotification,在某个视图控制器上,我弹出此通知设置消息: My app希望向您发送通知,其中可能包括警报、声音和图标徽章。这些可以在“设置”中配置 如何处理邮件的不允许和允许按钮 如果用户点击Allow,我需要更改同一视图控制器中的标签文本。我假设您的应用程序中有这样的代码: UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:... categories:...]; [application

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

My app
希望向您发送通知,其中可能包括警报、声音和图标徽章。这些可以在“设置”中配置

如何处理邮件的
不允许
允许
按钮


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

我假设您的应用程序中有这样的代码:

UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:... categories:...];
[application registerUserNotificationSettings:settings];
完成此操作后,系统将显示有关您正在谈论的内容的警报。此时,应用程序将收到
UIApplicationWillResignActiveNotification
(您可以注册该应用程序内代理或通过
NSNotificationCenter
)。然后,在用户做出一些选择后,系统将发送
UIApplicationIDBecMeactivityfication
(也可通过应用程序内委托或通知)。此时,请使用如下代码检查权限:

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

我假设你的应用程序中有这样的代码:

UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:... categories:...];
[application registerUserNotificationSettings:settings];
完成此操作后,系统将显示有关您正在谈论的内容的警报。此时,应用程序将收到
UIApplicationWillResignActiveNotification
(您可以注册该应用程序内代理或通过
NSNotificationCenter
)。然后,在用户做出一些选择后,系统将发送
UIApplicationIDBecMeactivityfication
(也可通过应用程序内委托或通知)。此时,请使用如下代码检查权限:

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

下面的答案解决了这个问题

当系统级弹出消息可见时,应用程序将调用resignActivity。当您单击“允许”“不允许”警报按钮时,您的警报消息将被解除,它将调用
AppDelegate
类中的
ApplicationIDBecomeActive
,同时向NSNotificationCenter注册,用户立即可以更改文本

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

下面的答案解决了这个问题

当系统级弹出消息可见时,应用程序将调用resignActivity。当您单击“允许”“不允许”警报按钮时,您的警报消息将被解除,它将调用
AppDelegate
类中的
ApplicationIDBecomeActive
,同时向NSNotificationCenter注册,用户立即可以更改文本

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