[英]How to detect if user tap on “Don't Allow” on Apple's push notification confirmation alert
I want to fire some event if user taps on "Don't Allow" button on the apple's push notification alert message. 如果用户点击苹果推送通知提醒消息上的“不允许”按钮,我想发出一些事件。 Is there any notification getting fired or any other way to detect this action from the user?
是否有任何通知被触发或以其他方式检测用户的此操作?
I'm sure someone will need a solid and simple answer to this (like I once did) -- so here you go. 我相信有人会需要一个坚实而简单的答案(就像我曾经做过的那样) - 所以你走了。 Directly after calling
[[UIApplication sharedApplication] registerForRemoteNotifications];
调用
[[UIApplication sharedApplication] registerForRemoteNotifications];
后直接调用[[UIApplication sharedApplication] registerForRemoteNotifications];
you can use NSNotificationCenter
beautifully like so: 您可以如此精美地使用
NSNotificationCenter
:
[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidBecomeActiveNotification
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification * _Nonnull note) {
if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications]) {
//user tapped "Allow"
}
else{
//user tapped "Don't Allow"
}
}];
NOTE: My device is currently running iOS 9.2, my Xcode is version 7.2, and my Deployment Target is 8.0. 注意:我的设备当前正在运行iOS 9.2,我的Xcode是版本7.2,而我的部署目标是8.0。
I do't thing so that we can detect what UIAlertView
button user pressed as there is no any kind of callback methods or delegate etc provided in iOS. 我不能这样我们可以检测
UIAlertView
按钮用户按下了什么,因为在iOS中没有提供任何类型的回调方法或委托等。
Only if you pressed Don't Allow
this will disable the push notification service for that particular iOS App and if YES then enable. 仅当您按下
Don't Allow
才会禁用该特定iOS应用程序的推送通知服务,如果是,则启用。
And After that through the code we can check and ensure about it using. 之后通过代码我们可以检查并确保使用它。
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (types == UIRemoteNotificationTypeNone)
// NONE
iOS8 comes with rregisterUserNotificationSettings: delegate method. Using this method we can do some patches.Please review them and Let us know your comments.Please these is only work with iOS8.
=> Add/Register Notification. =>添加/注册通知。
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)])
{
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
}
=> Here Below method is called After Alert Notification Fire. => 此处下面的方法称为警报通知火灾后。 Using Any of the Button Action(Don't allow or Allow) we force fully register Notification.
使用任何按钮操作(不允许或允许)我们强制完全注册通知。 and Dow with some patch Here.
和陶氏在这里有一些补丁。
#ifdef __IPHONE_8_0
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
//register to receive notifications
[application registerForRemoteNotifications];
}
=>We do some trick here =>我们在这里做一些技巧
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
NSLog(@"devToken: %@",devToken);
#if !TARGET_IPHONE_SIMULATOR
NSString* deviceToken = [[[[[devToken description]
stringByReplacingOccurrencesOfString: @"<" withString: @""]
stringByReplacingOccurrencesOfString: @">" withString: @""]
stringByReplacingOccurrencesOfString: @" " withString: @""] retain];
NSLog(@"deviceToken : %@",deviceToken);
NSUserDefaults *standardDefaults = [NSUserDefaults standardUserDefaults];
if((![[standardDefaults valueForKey:@"DeviceToken"] isEqualToString:deviceToken]) || [standardDefaults valueForKey:@"DeviceToken"]==nil){
[self sendProviderDeviceToken:deviceToken];
}else{
//Do Some Stuff Here
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.