This is the code I used before the UIAlertView was deprecated:
//OLD UIALERTVIEW - (void)applicationDidBecomeActive:(UIApplication *)application { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. // check to see if newer version exists to alert the user BOOL updateAvailable = NO; NSDictionary *updateDictionary = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:@"PLIST_URL_HERE"]]; NSArray *items = [updateDictionary objectForKey:@"items"]; NSDictionary *itemDict = [items lastObject]; NSDictionary *metaData = [itemDict objectForKey:@"metadata"]; NSString *newversion = [metaData valueForKey:@"bundle-version"]; NSString *currentversion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]; //updateAvailable = [newversion compare:currentversion options:NSNumericSearch] == NSOrderedDescending; //default code updateAvailable = [@"1.3" compare:currentversion options:NSNumericSearch] == NSOrderedDescending; //force update //updateAvailable = [@"1.1" compare:currentversion options:NSNumericSearch] == NSOrderedDescending; //force no update if (updateAvailable) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UPDATE AVAILABLE" message:@"Click OK to update the application to the latest version" delegate:self cancelButtonTitle:@"Later" otherButtonTitles:@"OK", nil]; [alert show]; } } -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if (buttonIndex != [alertView cancelButtonIndex]) { // point to the pList on dropbox to install the [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"PLIST_URL_HERE"]]; exit(0);
I am trying to update it to use UIAlertController instead. heres the code i use for this
//NEW UIACTIONCONTROLLER - (void)applicationDidBecomeActive:(UIApplication *)application { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. // check to see if newer version exists to alert the user BOOL updateAvailable = NO; NSDictionary *updateDictionary = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:@"PLIST_URL_HERE"]]; NSArray *items = [updateDictionary objectForKey:@"items"]; NSDictionary *itemDict = [items lastObject]; NSDictionary *metaData = [itemDict objectForKey:@"metadata"]; NSString *newversion = [metaData valueForKey:@"bundle-version"]; NSString *currentversion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]; //updateAvailable = [newversion compare:currentversion options:NSNumericSearch] == NSOrderedDescending; //default code updateAvailable = [@"1.3" compare:currentversion options:NSNumericSearch] == NSOrderedDescending; //force update //updateAvailable = [@"1.1" compare:currentversion options:NSNumericSearch] == NSOrderedDescending; //force no update if (updateAvailable) { UIAlertController * alert= [UIAlertController alertControllerWithTitle:@"UPDATE AVAILABLE" message:@"Click OK to update the application to the latest version" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"PLIST_URL_HERE"]]; exit(0); }]; UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]; [alert addAction:ok]; [alert addAction:cancel]; [self presentViewController:alert animated:YES completion:nil]; } }
The problem is this code:
[self presentViewController: warning animated: YES termination: zero];
gives me this error:
/Users/liz/Desktop/CactusQueuesGit/CactusQueue/AppDelegate.m:154:15: No visible @interface for 'AppDelegate' declares a selector 'presentViewController: animated: completion:'
I can put this code in viewDidLoad , but I donβt want the warning to appear every time users go to TableView. I just want it to load ONLY when the application opens.
How can i do this?
ios objective-c uialertcontroller
lizzy91
source share