Does UI_USER_INTERFACE_IDIOM work with Targeted Device Family

邮差的信 提交于 2019-12-08 02:51:38

问题


So I'm currently using UI_USER_INTERFACE_IDIOM in conjunction with [[UIDevice currentDevice] model] to check if I'm on an iPhone, iPod or iPad. What I've found is that in the iPad simulator 3.2, UI_USER_INTERFACE_IDIOM still evaluates to UIUserInterfaceIdiomPhone (iPhone).

I'm wondering if this has something to do with my Targeted Device Family setting. I'm only targeting iPhone for my App (I don't want to make a universal app with scaling views). However, I support the 3.2 SDK so I still want users that have an iPad to be able to run my iPhone app. Will UI_USER_INTERFACE_IDIOM evaluate correctly on the iPad even when I'm targeting iPhone?


回答1:


UI_USER_INTERFACE_IDIOM does not check if the device is an iPhone or iPad. What it checks is whether the user interface is in iPhone mode (the 1x/2x thing) or iPad mode.

If an app isn't configured to target iPad, it will always return UIUserInterfaceIdiomPhone because the UI is an iPhone app. It is a feature by design.

And even if the app is configured to target iPhone only, the iPad should be able to run it without any problems as long as you use the methods as documented.

(If you need iPad-specific capabilities, do not check whether the device really is an iPad. Instead, check for individual capability.)




回答2:


Best I can offer is that on the iPad simulator (3.2) while running in "iPhone" mode the

NSLog(@"model : %@", [UIDevice currentDevice].model);

returns

model : iPhone Simulator

(as a note: I am building for "iPhone" only and thus running in the iPhone experience on iPad. I have to assume the "model" name returned is affected by that)




回答3:


As people have said, check the individual capability.

For making a call, do this

// Only show the button if its is a device capable of making calls
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel:"]]) {
    self.Button.hidden = NO;
} else {
    self.Button.hidden = YES;
}


来源:https://stackoverflow.com/questions/3167740/does-ui-user-interface-idiom-work-with-targeted-device-family

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!