AndyD273
AndyD273

Reputation: 7279

UIAlertController throws NSInvalidArgumentException

I'm trying to get an alert to pop up with UIAlertController, but I keep getting this error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target <States: 0x17557b90>.'

if([InAppPurchaseVerifier hasSubscription]){

    NSUInteger row = [indexPath row];
    NSDictionary *myDict = [[NSDictionary alloc] initWithDictionary:[self.fullList objectAtIndex:row]];

    NSString *state = [[NSString alloc] initWithString: [myDict objectForKey:@"0"]];
    NSString *stateDetails = [[NSString alloc] initWithString: [myDict objectForKey:@"1"]];

    OfficeInfo *anotherViewController = [[OfficeInfo alloc] initWithNibName:@"OfficeInfo" bundle:nil];
    anotherViewController.stateName = state;
    anotherViewController.stateDetails = stateDetails;

    [state release];
    [stateDetails release];

    [self.navigationController pushViewController:anotherViewController animated:YES];
    [anotherViewController release];
}else{
    UIAlertController* alert = [[UIAlertController init] alertControllerWithTitle:@"Subscription Needed" message:@"You need to subscribe in order to access that. If you already have a subscription you may need to restore it" preferredStyle:UIAlertControllerStyleAlert];
    [self presentViewController:alert animated:YES completion:nil]; // Error throws here
}

Upvotes: 2

Views: 1307

Answers (1)

i_am_jorf
i_am_jorf

Reputation: 54600

UIAlertController is only available in iOS 8. For previous versions, you must check and fallback to the old code path, continue to use the deprecated API, or write a happy little wrapper object.

Upvotes: 8

Related Questions