From 5c5daa1348f5a65c3a7df875d9389ca0dfcfc756 Mon Sep 17 00:00:00 2001 From: JerryZhou Date: Thu, 5 Jan 2017 19:29:41 +0800 Subject: [PATCH] Fix UIAlertView deprecated in iOS 9.0 plus --- TTOpenInAppActivity/TTOpenInAppActivity.m | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/TTOpenInAppActivity/TTOpenInAppActivity.m b/TTOpenInAppActivity/TTOpenInAppActivity.m index 322a211..5b0278c 100755 --- a/TTOpenInAppActivity/TTOpenInAppActivity.m +++ b/TTOpenInAppActivity/TTOpenInAppActivity.m @@ -183,12 +183,22 @@ - (void)openDocumentInteractionControllerWithFileURL:(NSURL *)fileURL NSString *message = [NSString stringWithFormat:NSLocalizedStringFromTableInBundle(@"Your %@ doesn't seem to have any other Apps installed that can open this document.", @"TTOpenInAppActivityLocalizable", [TTOpenInAppActivity bundle], nil), deviceType]; // Display alert - UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedStringFromTableInBundle(@"No suitable App installed", @"TTOpenInAppActivityLocalizable", [TTOpenInAppActivity bundle], nil) - message:message - delegate:nil - cancelButtonTitle:NSLocalizedStringFromTableInBundle(@"OK", @"TTOpenInAppActivityLocalizable", [TTOpenInAppActivity bundle], nil) - otherButtonTitles:nil]; - [alert show]; + // #available(iOS 9.0, *) + if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0){ + UIAlertController* alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"No suitable App installed", nil) + message:message + preferredStyle:UIAlertControllerStyleAlert]; + UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {}]; + [alert addAction:cancelAction]; + [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alert animated:YES completion:nil]; + }else{ + UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedStringFromTableInBundle(@"No suitable App installed", @"TTOpenInAppActivityLocalizable", [TTOpenInAppActivity bundle], nil) + message:message + delegate:nil + cancelButtonTitle:NSLocalizedStringFromTableInBundle(@"OK", @"TTOpenInAppActivityLocalizable", [TTOpenInAppActivity bundle], nil) + otherButtonTitles:nil]; + [alert show]; + } // Inform app that the activity has finished // Return NO because the service was canceled and did not finish because of an error.