MugunthKumar / MKStoreKit

The "Goto" In App Purchases Framework for iOS 8+
2.09k stars 430 forks source link

Xcode warning: UIAlertView is deprecated #264

Open funnel20 opened 7 years ago

funnel20 commented 7 years ago

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;
  }