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

Xcode warning: UIAlertView is deprecated #264

@funnel20

Description

@funnel20

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions