iOS 开发:如何阻止 iPad 在 iPad 模式下运行通用应用程序?
我正在深入研究 iOS 开发,并创建了一个通用应用程序,该应用程序变成了仅适用于 iPhone 的应用程序。当它在 iPad 上运行时,它只会加载一个白屏,因为还没有编写 iPad 代码。我希望它能在 iPad 上以“iPhone”模式运行,如果它最终能在 iPad 上运行的话。我将“目标设备系列”属性设置为“iPhone”,这样应该可以防止它作为 iPad 应用程序出现在 App Store 中,但如果有人同时拥有 iPad 和 iPhone,则该应用程序最终可能会同步到 iPad,此时它只会加载白屏,因为它会尝试在 iPad 模式下运行应用程序,而它没有任何代码支持。在这种情况下,我更喜欢它实际上在 iPad 上运行,但以 iPhone 模式运行。
我的问题是...
- 当 iPad 运行通用应用程序时,它如何知道在“iPhone 模式”下运行它或执行 iPad 特定代码?
- 在通用应用程序中,它如何知道哪个代码是 iPhone,哪个代码是 iPad?
- 如何防止 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...
- 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
我假设您真正想要的是删除“通用”功能,而只是将其设为 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.
iPad 会查找
目标设备系列
,如果 iPad 不存在,则它知道必须在 iPhone 模式下运行该应用程序。当您为应用程序编写代码时,如果您需要为每个设备执行特定操作,则必须指定您的目标设备。 (请参阅下面的代码示例)
您的
目标设备系列
不支持 iPad。其次,在您的代码中,不要指定特定代码需要特定设备,例如: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.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)
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:如果您构建通用应用程序,它将使用您的 iPad 代码。无法在“iPhone 模式”下运行通用应用程序。 Apple 将检查您是否遵循 iPad 设计规范。
在通用应用程序中,有两个应用程序委托:AppDelegate_iPhone.h 和 AppDelegate_iPad.h
您可以在AppDelegate_iPad 中添加您的iPhone 代码,但Apple 不会满意。
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.
您不应该将其添加到您的 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!
我认为每个设备的 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.
另一种方法(使用代码)是:
在应用程序的 AppDelegate 中(如果您的应用程序是作为通用应用程序创建的),您可以找到以下代码:
您可以在其中自定义要显示的视图。
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:
There you can customize what view to show.
从
Xcode 5
开始,您可以从项目中选择开发目标设备:从
Development Info
内的设备部分,现在您可以选择:Since
Xcode 5
, you can chose your development target devices from the Project:From the devices section within
Development Info
, now you can choose:我认为您的配置有问题,因为如果您的代码仅针对 iPhone 设备,则该应用程序将可以在具有专为 iPhone 设计的屏幕的 iPad 上运行(因此,减少了,有可能 x2)。
[[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).
[[UIDevice currentDevice] userInterfaceIdiom]
mentioned supra...