开发者

iPhone development: what will [[UIDevice currentDevice] model] return for "iPad"? [closed]

开发者 https://www.devze.com 2022-12-24 13:44 出处:网络
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.

Closed 8 years ago.

开发者_开发百科 Improve this question

What will [[UIDevice currentDevice] model] return for "iPad"?


I tried using containsString but it was not allowed with xcode4

Here is how I solved it:

if ([[[UIDevice currentDevice] model] hasPrefix:@"iPhone"])
    {

Hope this helps even if its a bit late.


You can use UI_USER_INTERFACE_IDIOM(), which will either return UIUserInterfaceIdiomPhone or UIUserInterfaceIdiomPad. Bear in mind that on any device < 3.2, this is unavailable, so first check to see whether the property can be retrieved - in this case, it is not an iPad.

Or, alternatively, to specifically work out whether the platform is an iPad or not, use

if ([[[UIDevice currentDevice] model] containsString:@"iPad"]) {
    // Your code goes here
}

Hope this helps ;)


Well trying on simulator:

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

it gives iPad Simulator, will update the answer when I will get the device ;)


You might try the Apple Developer Forums.

0

精彩评论

暂无评论...
验证码 换一张
取 消