Jov*_*van 25 push-notification apple-push-notifications ios
我想实现一个自定义屏幕,通知我的用户我为什么要请求推送通知权限.在他们按下该自定义屏幕中的按钮后,我会显示iOS推送通知权限对话框[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
如果用户尚未看到推送通知权限对话框,我只想显示此自定义屏幕一次.我不能使用,[[UIApplication sharedApplication] enabledRemoteNotificationTypes] == UIRemoteNotificationTypeNone因为如果用户决定不允许推送通知,这也将返回'none'.
任何人的想法?
小智 6
您可以使用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];
}
Run Code Online (Sandbox Code Playgroud)
和
- (void)alertView:(UIAlertView*)alertView didDismissWithButtonIndex:(NSInteger)index {
// Actually registering to push notifications
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5484 次 |
| 最近记录: |