gpt4 book ai didi

ios - 如何知道推送通知权限警报是否已经显示

转载 作者:IT王子 更新时间:2023-10-29 07:58:05 25 4
gpt4 key购买 nike

我想实现一个自定义屏幕,通知我的用户我为什么要请求推送通知权限。在他们按下自定义屏幕中的按钮后,我使用 [[UIApplication sharedApplication] registerForRemoteNotificationTypes:

显示 iOS 推送通知权限对话框

如果用户还没有看到推送通知权限对话框,我只想显示此自定义屏幕一次。我不能使用 [[UIApplication sharedApplication] enabledRemoteNotificationTypes] == UIRemoteNotificationTypeNone,因为如果用户决定不允许推送通知,这也会返回“无”。

有什么想法吗?

最佳答案

你可以使用 NSUserDefaults :

#define kPushNotificationRequestAlreadySeen @"PushNotificationRequestAlreadySeen"

if(![[NSUserDefaults standardUserDefaults] boolForKey:kPushNotificationRequestAlreadySeen]) {

// Notify the user why you want to have push notifications
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:... delegate:self ...];
[alertView show];

[[NSUserDefaults standardUserDefaults] setBool:YES forKey:kPushNotificationRequestAlreadySeen];
}
else {
// Already allowed -> register without notifying the user
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound];
}

- (void)alertView:(UIAlertView*)alertView didDismissWithButtonIndex:(NSInteger)index {
// Actually registering to push notifications
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound];
}

关于ios - 如何知道推送通知权限警报是否已经显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25264203/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com