无法将设备检测为iPad [英] Cannot detect device as iPad

查看:202
本文介绍了无法将设备检测为iPad的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一款使用HealthKit的应用。该应用程序不能在iPad上运行,因此我的 viewDidLoad 方法包含一个if / then / else语句,以向iPad用户显示警报。这是我的代码:

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.");
    }];
}

SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@8.0)位来自这个要点

UIAlertController应显示设备何时是iPad,未运行iOS 8.0+,或者只是(由于某些其他原因)无法使用HealthKit。这在纸上都很好,但是当我在运行iOS 8的iPad 2模拟器上运行应用程序时,应用程序正常启动并且不显示警报。为了记录,我知道警报没有按钮但我不知道它不希望它消失。它应该仅在iPad或低于iOS 8的设备上显示,因此当它显示时不应该消失。

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.

那么为什么我的应用程序没有在iPad上显示警报视图?控制台显示没有错误。

So why is my app not showing the alert view on iPad? The console shows no errors.

编辑:没有按钮的通知不会出现在最终产品中,只是在测试中。然而,这一点仍然存在,因为警报仍应显示。

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.

推荐答案

您是否检查过设备系列是否已设置普及?如果将其设置为iPhone,则用户习惯用法永远不会是iPad。使应用程序通用似乎已解决了此问题中提出的类似问题

Have you checked that the device family is set to universal? If it is set to iPhone only the user idiom will never be iPad. Making the app universal seems to have resolved a similar problem asked in this question

PS,我的第一个答案道歉没有正确阅读问题。

PS, Apologies for my first answer not reading the question properly.

这篇关于无法将设备检测为iPad的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆