xcode 如何在 iPhone 3.1.3 模拟器上运行通用应用程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2759229/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I run a universal app on the iPhone 3.1.3 simulator?
提问by bpapa
I'm working on a new app that I want to be universal for the iPhone and iPad. I started out with the "Create a Window-based app" wizard, and it created separate app delegates in "iPhone" and "iPad" groups. Since I already was quite familiar with iPhone dev, I did that part of my project, and now I'm ready to do some iPad stuff.
我正在开发一个新的应用程序,我希望它可以在 iPhone 和 iPad 上通用。我从“创建基于窗口的应用程序”向导开始,它在“iPhone”和“iPad”组中创建了单独的应用程序委托。因为我已经非常熟悉 iPhone 开发,所以我做了我项目的那部分,现在我准备做一些 iPad 的东西。
So... I started out by adding a UISplitViewController to my iPad delegate, switch the Active SDK to 3.2, and it works! But when I switch back to 3.1.3, and try to run it in the simulator, Build and Go fails. For starters, I see:
所以......我开始向我的 iPad 委托添加一个 UISplitViewController,将 Active SDK 切换到 3.2,它工作正常!但是当我切换回 3.1.3 并尝试在模拟器中运行它时,Build and Go 失败了。首先,我看到:
...path.../iPad/AppDelegate_Pad.h:13: error: expected specifier-qualifier-list before 'UISplitViewController'
...路径.../iPad/AppDelegate_Pad.h:13: 错误:'UISplitViewController' 之前的预期说明符限定符列表
I've got my Base SDK set to 3.2 and my Deployment Target set to 3.1.3. I thought that was enough. But I also have found in the documentation this method to conditionally compile:
我已将 Base SDK 设置为 3.2,并将部署目标设置为 3.1.3。我以为这就够了。但我也在文档中找到了这种有条件编译的方法:
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
MyIPadViewController* vc;
// Create the iPad view controller
#else
MyIPhoneViewController* vc;
// Create the iPhone view controller
#endif
So do I need to do this everywhere? It seems like an awful lot of code to add (that I'll be getting rid of in a short time for 4.0 anyway) so I feel like I must be doing something wrong. And, I don't even have any idea how this works for things like @property or @synthesize declarations.
那么我需要在任何地方都这样做吗?似乎要添加大量代码(无论如何我将在短时间内摆脱 4.0),所以我觉得我一定做错了什么。而且,我什至不知道这对@property 或@synthesize 声明之类的东西是如何工作的。
tl;dr version of the question - did I miss a setting somewhere?
tl; dr 版本的问题 - 我是否错过了某个地方的设置?
回答by progrmr
I use this C function to help keep the code concise:
我使用这个 C 函数来帮助保持代码简洁:
BOOL isPad() {
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
}
Another thing I do, when I have different xib files for iPhone vs iPad. I have a stripPadSuffixOnPhone() function that helps keep the code simpler:
我做的另一件事是,当我为 iPhone 和 iPad 使用不同的 xib 文件时。我有一个 stripPadSuffixOnPhone() 函数可以帮助简化代码:
// Load/create the Delete table cell with delete button
self.deleteCell = [Utilities loadNib:stripPadSuffixOnPhone(@"DeleteCell~ipad")
ClassName:@"DeleteCell"
Owner:self];
Things like that can make coding more straightforward and a lot less conditionals. Still have to test everything twice though.
像这样的事情可以使编码更简单,条件也少得多。尽管如此,仍然必须对所有内容进行两次测试。
回答by Ole Begemann
Quite the opposite. A universal app runs the same binary on iPhone and iPad so you cannot use conditional compilation to differentiate between the two version. But you need to use the macro Apple cites in the documentation:
恰恰相反。通用应用程序在 iPhone 和 iPad 上运行相同的二进制文件,因此您不能使用条件编译来区分这两个版本。但是您需要使用 Apple 在文档中引用的宏:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// iPad-specific code
} else {
// iPhone-specific code
}
回答by Bob Withers
Here's what works for me:
以下是对我有用的内容:
- Build your app using SDK 3.2.
- Switch the active SDK to iPhone Simulator 3.1.3 (or whatever).
- From the Run menu select Debug (not Build and Debug).
- 使用 SDK 3.2 构建您的应用程序。
- 将活动 SDK 切换到 iPhone Simulator 3.1.3(或其他)。
- 从运行菜单中选择调试(不是构建和调试)。
The binary built under 3.2 will be installed in the 3.x simulator without rebuilding. When you are finished don't forget to set your active SDK back to 3.2.
在 3.2 下构建的二进制文件将安装在 3.x 模拟器中,无需重建。完成后不要忘记将活动 SDK 设置回 3.2。