From c25e581d4f8a04fe179fe2e31d5124093bc0dd53 Mon Sep 17 00:00:00 2001 From: Alex Liu Date: Tue, 19 Jun 2018 14:19:27 -0400 Subject: [PATCH 1/2] Updated deprecated UIAlertView to UIAlertController --- MLeaksFinder/MLeaksMessenger.m | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/MLeaksFinder/MLeaksMessenger.m b/MLeaksFinder/MLeaksMessenger.m index 70a85a5..c4132c6 100644 --- a/MLeaksFinder/MLeaksMessenger.m +++ b/MLeaksFinder/MLeaksMessenger.m @@ -25,13 +25,16 @@ + (void)alertWithTitle:(NSString *)title delegate:(id)delegate additionalButtonTitle:(NSString *)additionalButtonTitle { [alertView dismissWithClickedButtonIndex:0 animated:NO]; - UIAlertView *alertViewTemp = [[UIAlertView alloc] initWithTitle:title - message:message - delegate:delegate - cancelButtonTitle:@"OK" - otherButtonTitles:additionalButtonTitle, nil]; - [alertViewTemp show]; - alertView = alertViewTemp; + UIAlertController * alertView = [UIAlertController + alertControllerWithTitle:title + message:message + preferredStyle:UIAlertControllerStyleAlert]; + + UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){ + //do something when click button + }]; + [alertView addAction:okAction]; + [[[[UIApplication sharedApplication] keyWindow] rootViewController] presentViewController:alertView animated:YES completion:nil]; NSLog(@"%@: %@", title, message); } From 789fa28203d1eb34f9f8a812620decb46bd28392 Mon Sep 17 00:00:00 2001 From: Alex Liu Date: Tue, 19 Jun 2018 14:42:44 -0400 Subject: [PATCH 2/2] Updated availability for iOS 9 or prior --- MLeaksFinder/MLeaksMessenger.m | 35 ++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/MLeaksFinder/MLeaksMessenger.m b/MLeaksFinder/MLeaksMessenger.m index c4132c6..2c0b9f5 100644 --- a/MLeaksFinder/MLeaksMessenger.m +++ b/MLeaksFinder/MLeaksMessenger.m @@ -12,7 +12,11 @@ #import "MLeaksMessenger.h" +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 90000 static __weak UIAlertView *alertView; +#else +static __weak UIAlertView *alertView; +#endif @implementation MLeaksMessenger @@ -25,16 +29,27 @@ + (void)alertWithTitle:(NSString *)title delegate:(id)delegate additionalButtonTitle:(NSString *)additionalButtonTitle { [alertView dismissWithClickedButtonIndex:0 animated:NO]; - UIAlertController * alertView = [UIAlertController - alertControllerWithTitle:title - message:message - preferredStyle:UIAlertControllerStyleAlert]; - - UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){ - //do something when click button - }]; - [alertView addAction:okAction]; - [[[[UIApplication sharedApplication] keyWindow] rootViewController] presentViewController:alertView animated:YES completion:nil]; + if (@available(iOS 9, *)) { + UIAlertController * alertViewTemp = [UIAlertController + alertControllerWithTitle:title + message:message + preferredStyle:UIAlertControllerStyleAlert]; + + UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){ + //do something when click button + }]; + [alertViewTemp addAction:okAction]; + [[[[UIApplication sharedApplication] keyWindow] rootViewController] presentViewController:alertViewTemp animated:YES completion:nil]; + } + else{ + UIAlertView *alertViewTemp = [[UIAlertView alloc] initWithTitle:title + message:message + delegate:delegate + cancelButtonTitle:@"OK" + otherButtonTitles:additionalButtonTitle, nil]; + [alertViewTemp show]; + alertView = alertViewTemp; + } NSLog(@"%@: %@", title, message); }