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

拜拜、爱过 提交于 2019-11-30 11:38:37
  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.

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 */
}
  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.

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