Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

Xcode warning: UIAlertView is deprecated #264

Open
funnel20 opened this issue Mar 15, 2017 · 0 comments
Open

Xcode warning: UIAlertView is deprecated #264

funnel20 opened this issue Mar 15, 2017 · 0 comments

Comments

@funnel20
Copy link

UIAlertView is deprecated in iOS 8.0, as it's superseded by UIAlertController.

Hence changed the code in 'initiatePaymentRequestForProductWithIdentifier:' to switch between UIAlertView and UIAlertController in case the latter exists. Also suppressed the deprecation warning for UIAlertView:

  if (![SKPaymentQueue canMakePayments]) {
#if TARGET_OS_IPHONE
      if ([UIAlertController class]) {
          // iOS 8.0+
          UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"In App Purchasing Disabled", @"")
                                                                         message:NSLocalizedString(@"Check your parental control settings and try again later", @"")
                                                                  preferredStyle:UIAlertControllerStyleAlert];
          
          UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Okay", @"")
                                                                 style:UIAlertActionStyleCancel
                                                               handler:nil];
          
          [alert addAction:cancelAction];
          
          // Show Alert:
          [[[[UIApplication sharedApplication] keyWindow] rootViewController] presentViewController:alert
                                                                                           animated:YES
                                                                                         completion:nil];
      }
      else {
          // Before iOS 8.0:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
          [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"In App Purchasing Disabled", @"")
                                      message:NSLocalizedString(@"Check your parental control settings and try again later", @"")
                                     delegate:self
                            cancelButtonTitle:NSLocalizedString(@"Okay", @"")
                            otherButtonTitles:nil] show];
#pragma clang diagnostic pop
      }
#elif TARGET_OS_MAC
    NSAlert *alert = [[NSAlert alloc] init];
    alert.messageText = NSLocalizedString(@"In App Purchasing Disabled", @"");
    alert.informativeText = NSLocalizedString(@"Check your parental control settings and try again later", @"");
    [alert runModal];
#endif
    return;
  }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant