在某些视图控制器中,我弹出此通知设置消息:
中配置
My app
希望向您发送通知,其中可能包含提醒,声音和图标徽章。这些可以在设置
如何处理短信的Don't Allow
和Allow
按钮?
如果用户点击Allow
,我需要更改同一视图控制器中的标签文字。
答案 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")
});