简体   繁体   English

如何检测用户是否在Apple的推送通知确认提醒中点击“不允许”

[英]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.

相关问题 跟踪用户对推送通知的选择[允许/禁止] - track user choice for Push Notification [allow/don't] 检测用户对“允许推送”通知对话框的响应 - detect user response to the Allow Push notification dialog 如何检测用户是否不允许Apple Health Kit授权? - How to detect if the user doesn't allow Apple Health Kit Authorisation? 如何检测用户卸载的iOS App? 我需要推送严肃的通知。 我不想失去它 - How to detect user uninstalled iOS App? I need push serious notification. I don't wanna lose it 如何检测用户选择不允许MKMapView for iphone - How to detect user selects Don't Allow for MKMapView for iphone 如何检测用户已单击“不允许访问摄像头” - How to detect user has clicked Don't Allow access to camera phonegap ios:当用户为权限请求框选择“不允许”时,推送通知冻结 - phonegap ios: push notification freezes when user selected “Don't Allow” for the permission request box 如果用户在目标c中允许推送通知,如何显示警报以感谢您 - How it is possible to show a alert for thank you if user allow push notification in objective c 点击苹果手表推送通知问题 - Tap apple watch push notification issue 当用户下次不允许点击时如何显示用户位置? - How to show user location when user tap don't allow for the next time?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM