I am familiar with checking if I am on iPad using (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad).
But, this is true only for universal apps.
I wonder if there is a way to know I am on iPad running an iPhone app.
Thanks!
You could use [[UIDevice currentDevice] model].
I think even then it gives the right device indication..
As UIDevice uses a shared class through out the device, it should give iPad only what ever type of the app is..
Have you tried it.?
As per the apple, and enum defined in UIDevice class it is like this
typedef NS_ENUM(NSInteger, UIUserInterfaceIdiom) {
#if __IPHONE_3_2 <= __IPHONE_OS_VERSION_MAX_ALLOWED
UIUserInterfaceIdiomPhone, // iPhone and iPod touch style UI
UIUserInterfaceIdiomPad, // iPad style UI
#endif
};
Here you can see that it enum just gives the which style of UI it is using, as it is iPhone app running in iPhone style UI it gives as UIUserInterfaceIdiomPhone
And also the name itself says that UserInterfaceIdiom it means it relate to UI screen size.
Instead you can use
[[UIDevice currentDevice] model];
Which gives the exact device model, here you can check for range of string "iPad" to identify the device.
Just finished up my iPhone appln, now wants to use same appln for creating an iPad version. What i really want to do is to detect which on which device the app is running and accordingly pick UI at runtime. I get some code regarding which is my current device. Basically main idea behind is that is i don't want to write the server-client communication part again for separate ipad version. Ui is different hence I don't want to create a universal app for this.
My Prob: What settings should I do to make to work the application as described above. Currently when I run using iPhone Simulator, It says tht my current device is iPhone. But, when I changed my device to iPad Simulator and than run it back again, it convert that int iphone simulator.
Thanks.
you can check with this line:
NSString *model = [[NSString alloc]initWithString:[[UIDevice currentDevice] model]];
model value would be either iPhone or iPad
or you can go with [[UIDevice currentDevice] userInterfaceIdiom] and compare the values with
typedef enum {
UIUserInterfaceIdiomPhone,
UIUserInterfaceIdiomPad,
} UIUserInterfaceIdiom;
I'm diving into iOS development and I created a universal app that turned into an iPhone-only app. When it runs on the iPad, it just loads a white screen since there's no iPad code written yet. What I'd like is for it to run in "iPhone" mode on the iPad, if it somehow ends up on an iPad. I have the "Targeted Device Family" property set to "iPhone", so that should prevent it from showing up in the App Store as an iPad app, but if anyone owns both an iPad and an iPhone, then the app could end up synced to the iPad, at which point it will just load the white screen because it will try to run the app in iPad mode, which it doesn't have any code to support. In this situation, I prefer that it actually ran on the iPad, but in iPhone mode.
My questions are...
When an iPad runs a universal app, how does it know to run it in "iPhone mode" or execute the iPad specific code?
In a universal app, how does it know which code is iPhone and which code is iPad?
How can I prevent the iPad from trying to run the iPad code and, instead, run the iPhone code?
I apologize if I sound like a total noob, but I am. Thanks so much for your wisdom!
The iPad looks into the application's Info.plist, for the UIDeviceFamily key, which is an array. The value '1' indicates iPhone/iPod Touch, '2' indicates 'iPad'. If there's a '1' but no '2' then you get the simulated iPhone environment. This value is written to the Info.plist automatically as a result of your 'Targeted Device Family'. If you think you've set it to iPhone but are still getting an iPad build, check you didn't just set it for one build configuration. Check the Info.plist within your produced app bundle if you want to be really confident.
There's only one binary, which you write to launch correctly on either device.
Just don't target the iPad.
I'm assuming what you actually want is to remove the "universal" capability, and just make it an iPhone app.
In Xcode, go to Project => Edit Project Settings => Build.
Search for universal, or 'Targeted Device Family'.
Pick iPhone.
Goodbye iPad.
When an iPad runs a universal app, how does it know to run it in "iPhone mode" or execute the iPad specific code?
The iPad looks for the Targeted Device Family, if the iPad is not present, then it knows it must run the app in iPhone mode.
In a universal app, how does it know which code is iPhone and which code is iPad?
When you write the code for the app, you must specify what device you are targeting if there are specific things you need to do per device. (see the code example below)
How can I prevent the iPad from trying to run the iPad code and, instead, run the iPhone code?
Do not support iPad in your Targeted Device Family. Second, in your code, do not specify that specific code needs a specific device, for example:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
/* run something specific for the iPad */
}
else
{
/* run something specific for the iPhone */
}
If you build an universal app, it will use your iPad code. It is not possible to run a universal app in "iPhone Mode". Apple will check that you have followed the iPad design specifications.
In a universal app, there are two app-delegates: AppDelegate_iPhone.h and AppDelegate_iPad.h
You can add your iPhone code in the AppDelegate_iPad, but Apple will not be pleased.
You should NOT add this to your Info.plist file. Instead, add it to your build settings per Apple's suggestion. Specifically, use the TARGETED_DEVICE_FAMILY build setting.
If you are using storyboards, you also want to remove the UIMainStoryboardFile~ipad key from your Info.plist as it will be used regardless of your TARGETED_DEVICE_FAMILY setting.
Good luck!
I think there is an entry in the info.plist file for each of the devices that says which main window to load.
Maybe a quick and dirty solution would be to set both MainWindow-iPhone and MainWindow-iPad to the same -iPhone- main window.
Another way to do it (with code) is:
In your App's AppDelegate (if your App was created as an Universal App) you can find the following code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
//iPad...
} else {
//iPhone and iPod Touch...
}
return YES;
}
There you can customize what view to show.
Since Xcode 5, you can chose your development target devices from the Project:
From the devices section within Development Info, now you can choose:
1-iPhone 2- iPad 3- Universal
I think that something is wrong with your configuration, because if you target the code for iPhone only Device, the app will bu runnable on an iPad with the screen that was designed for iPhone (so, reduced, with the possibility to x2).
the proposals from the AppStore (iPhone/iPad/both) depend on the user's preferences
you can experiment it with the Simulator (and choose iPad as the Device)
the code is the same for iPad/iPhone ! ... unless you use [[UIDevice currentDevice] userInterfaceIdiom] mentioned supra...
Can I compile the same iPhone source code for iPad?
Yes. This is called a Universal binary.
Yes you can do so.
(If you simply want to run iPhone code on iPad)
Then When you select the base sdk as 3.2 it will run on iPad with a small 2x button at the right bottom Clicking on which will zoom the whole application as per the iPad screen but the images used will be blur.
(If you want it to make the code for both)
All you have to do is to set the Target Family in Build as iPhone/iPad instead of iPhone.
and set the frames as per iPad by certain condition recognizing you are running on iPhone or iPad.
That can be done by below set of code
BOOL kIS_IPAD;//GLOABAL VARIABLE
#ifdef UI_USER_INTERFACE_IDIOM()
#define IS_IPAD() (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#else
#define IS_IPAD() (false)
#endif
if (IS_IPAD()) {
kIsIPAD=YES;
}
else {
kIsIPAD=NO;
}
hAPPY cODING...
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?
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.)
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)
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;
}