0

My code.

UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
        center.delegate                  = self;
        [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert) completionHandler:^(BOOL granted, NSError * _Nullable error) {
            if (!error) {
                NSLog(@"~ios10-----");
                dispatch_async(dispatch_get_main_queue(), ^{
                    [[UIApplication sharedApplication] registerForRemoteNotifications];
                });

            }else{
                NSLog(@"~ios10---error--");
            }
        }];

This code in iPhone 5s ios 11.4.1 is work, didRegisterForRemoteNotificationsWithDeviceToken method called. But in iPhone 6s ios 13.5.0 doesn't work. After few days of googled, in APNS connection failure found a solution, fix was to change the phones to use an alternative DNS like Google (8.8.8.8) or Cloudflare (1.1.1.1) in the wifi settings. But I can't modify the DNS of the user's phone.

If you have any ideas, please let me know. Thanks

1 Answers1

0

you can try this,i hope this will help you.

if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) {
          UIUserNotificationType allNotificationTypes =
          (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
          UIUserNotificationSettings *settings =
          [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];
          [application registerUserNotificationSettings:settings];
      } else {
          // iOS 10 or later
  #if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
          // For iOS 10 display notification (sent via APNS)
          [UNUserNotificationCenter currentNotificationCenter].delegate = self;
          UNAuthorizationOptions authOptions =
          UNAuthorizationOptionAlert
          | UNAuthorizationOptionSound
          | UNAuthorizationOptionBadge;
          [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError * _Nullable error) {
          }];
  #endif
      }
Vandana pansuria
  • 764
  • 6
  • 14