Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Development: How can I prevent an iPad from running a universal app in iPad mode?

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...

  1. When an iPad runs a universal app, how does it know to run it in "iPhone mode" or execute the iPad specific code?
  2. In a universal app, how does it know which code is iPhone and which code is iPad?
  3. 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!

like image 822
BeachRunnerFred Avatar asked Feb 07 '11 16:02

BeachRunnerFred


People also ask

Can I block a specific app on iPad?

Here's how apps can be blocked from being downloaded: Step 1: Navigate to Inventory and click on Apps to view a list of all the available apps. Step 2: To block a specific app from being downloaded, select the app to be blocked on the devices and click on Blocklist App.


5 Answers

  1. 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.
  2. There's only one binary, which you write to launch correctly on either device.
  3. Just don't target the iPad.
like image 119
Tommy Avatar answered Sep 28 '22 18:09

Tommy


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.

like image 34
jv42 Avatar answered Sep 28 '22 17:09

jv42


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 */
}
like image 33
WrightsCS Avatar answered Sep 28 '22 16:09

WrightsCS


  1. 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.

  2. In a universal app, there are two app-delegates: AppDelegate_iPhone.h and AppDelegate_iPad.h

  3. You can add your iPhone code in the AppDelegate_iPad, but Apple will not be pleased.

like image 32
Manni Avatar answered Sep 28 '22 18:09

Manni


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!

like image 24
Erik Avatar answered Sep 28 '22 17:09

Erik