I'm making an app that uses HealthKit. The app must not work on an iPad, and as such my viewDidLoad
method contains an if/then/else statement to show an alert to iPad users. This is my code:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0") && [HKHealthStore isHealthDataAvailable] == 1) {
...
}
else {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Whoops!" message:@"Looks like your device doesn't support HealthKit :(" preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:alertController animated:1 completion:^(){
NSLog(@"Showed error alert because of unsupported device.");
}];
}
The SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")
bit is from this gist.
The UIAlertController should show when the device is an iPad, is not running iOS 8.0+, or just (for some other reason) cannot use HealthKit. This is all good on paper, but when I run the app on the iPad 2 simulator running iOS 8, the app launches as normal and does not show the alert. For the record, I know the alert has no buttons but I don't want it to go away. It should only show on an iPad or device with less than iOS 8, and as such shouldn't need to go away when it's shown.
So why is my app not showing the alert view on iPad? The console shows no errors.
EDIT: The notification without buttons will not be in the final product, just in testing. The point still remains, however, as the alert should still be showing up.