iOS 开发:如何阻止 iPad 在 iPad 模式下运行通用应用程序?

发布于 2024-10-16 09:36:02 字数 568 浏览 6 评论 0原文

我正在深入研究 iOS 开发,并创建了一个通用应用程序,该应用程序变成了仅适用于 iPhone 的应用程序。当它在 iPad 上运行时,它只会加载一个白屏,因为还没有编写 iPad 代码。我希望它能在 iPad 上以“iPhone”模式运行,如果它最终能在 iPad 上运行的话。我将“目标设备系列”属性设置为“iPhone”,这样应该可以防止它作为 iPad 应用程序出现在 App Store 中,但如果有人同时拥有 iPad 和 iPhone,则该应用程序最终可能会同步到 iPad,此时它只会加载白屏,因为它会尝试在 iPad 模式下运行应用程序,而它没有任何代码支持。在这种情况下,我更喜欢它实际上在 iPad 上运行,但以 iPhone 模式运行。

我的问题是...

  1. 当 iPad 运行通用应用程序时,它如何知道在“iPhone 模式”下运行它或执行 iPad 特定代码?
  2. 在通用应用程序中,它如何知道哪个代码是 iPhone,哪个代码是 iPad?
  3. 如何防止 iPad 尝试运行 iPad 代码,而转而运行 iPhone 代码?

如果我听起来像个十足的菜鸟,我很抱歉,但我确实是。非常感谢您的智慧!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

安人多梦 2024-10-23 09:36:02
  1. iPad 会在应用程序的 Info.plist 中查找 UIDeviceFamily 键(它是一个数组)。值“1”表示 iPhone/iPod Touch,“2”表示“iPad”。如果有“1”但没有“2”,那么您将获得模拟的 iPhone 环境。该值会根据您的“目标设备系列”自动写入 Info.plist。如果您认为已将其设置为 iPhone,但仍获得 iPad 版本,请检查您是否仅将其设置为一种版本配置。如果您想真正有信心,请检查生成的应用程序包中的 Info.plist。
  2. 只有一个二进制文件,您可以编写该二进制文件以在任一设备上正确启动。
  3. 只是不要瞄准iPad。
  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.
网名女生简单气质 2024-10-23 09:36:02

我假设您真正想要的是删除“通用”功能,而只是将其设为 iPhone 应用程序。

在 Xcode 中,转到 Project =>编辑项目设置 =>建造。

搜索通用或“目标设备系列”。

选择iPhone。

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

独自唱情﹋歌 2024-10-23 09:36:02

当 iPad 运行通用应用程序时,它如何知道以“iPhone 模式”运行它或执行 iPad 特定代码?

iPad 会查找目标设备系列,如果 iPad 不存在,则它知道必须在 iPhone 模式下运行该应用程序。

在通用应用程序中,它如何知道哪个代码是 iPhone,哪个代码是 iPad?

当您为应用程序编写代码时,如果您需要为每个设备执行特定操作,则必须指定您的目标设备。 (请参阅下面的代码示例)

如何阻止 iPad 尝试运行 iPad 代码,而转而运行 iPhone 代码?

您的目标设备系列不支持 iPad。其次,在您的代码中,不要指定特定代码需要特定设备,例如:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
{
    /* run something specific for the iPad */
} 
else
{
    /* run something specific for the iPhone */
}

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 */
}
笑叹一世浮沉 2024-10-23 09:36:02
  1. 如果您构建通用应用程序,它将使用您的 iPad 代码。无法在“iPhone 模式”下运行通用应用程序。 Apple 将检查您是否遵循 iPad 设计规范。

  2. 在通用应用程序中,有两个应用程序委托:AppDelegate_iPhone.h 和 AppDelegate_iPad.h

  3. 您可以在AppDelegate_iPad 中添加您的iPhone 代码,但Apple 不会满意。

  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.

我的黑色迷你裙 2024-10-23 09:36:02

您不应该将其添加到您的 Info.plist 文件中。相反,请按照 Apple 的 建议。具体来说,使用 TARGETED_DEVICE_FAMILY 构建设置。

如果您使用故事板,您还需要从 Info.plist 中删除 UIMainStoryboardFile~ipad 键,因为无论您的 TARGETED_DEVICE_FAMILY 设置如何,都会使用它。

祝你好运!

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!

ぽ尐不点ル 2024-10-23 09:36:02

我认为每个设备的 info.plist 文件中都有一个条目,说明要加载哪个主窗口。
也许一个快速但肮脏的解决方案是将 MainWindow-iPhone 和 MainWindow-iPad 设置为同一个 -iPhone- 主窗口。

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.

花辞树 2024-10-23 09:36:02

另一种方法(使用代码)是:

在应用程序的 AppDelegate 中(如果您的应用程序是作为通用应用程序创建的),您可以找到以下代码:

- (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;
}

您可以在其中自定义要显示的视图。

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.

对岸观火 2024-10-23 09:36:02

Xcode 5 开始,您可以从项目中选择开发目标设备:

Development Info 内的设备部分,现在您可以选择:

1-iPhone 2- iPad 3- 通用

在此处输入图像描述

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

enter image description here

风尘浪孓 2024-10-23 09:36:02

我认为您的配置有问题,因为如果您的代码仅针对 iPhone 设备,则该应用程序将可以在具有专为 iPhone 设计的屏幕的 iPad 上运行(因此,减少了,有可能 x2)。

  • AppStore(iPhone/iPad/两者)的建议取决于用户的偏好,
  • 您可以使用模拟器进行实验(并选择 iPad 作为设备),
  • iPad/iPhone 的代码相同! ...除非您使用上面提到的 [[UIDevice currentDevice] userInterfaceIdiom] ...

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...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文