ios 用于 iPhone 测试的通用 iPhone/iPad 应用程序调试编译错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2618889/
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
Universal iPhone/iPad application debug compilation error for iPhone testing
提问by andybee
I have written an iPhone and iPad universal app which runs fine in the iPad simulator on Xcode, but I would now like to test the iPhone functionality. I seem unable to run the iPhone simulator with this code as it always defaults to the iPad?
我已经编写了一个 iPhone 和 iPad 通用应用程序,它在 Xcode 上的 iPad 模拟器中运行良好,但我现在想测试 iPhone 的功能。我似乎无法使用此代码运行 iPhone 模拟器,因为它始终默认为 iPad?
Instead I tried to run on the device and as it begins to run I get the following error:
相反,我尝试在设备上运行,当它开始运行时,我收到以下错误:
dyld: Symbol not found: _OBJC_CLASS_$_UISplitViewController
Referenced from: /var/mobile/Applications/9770ACFA-0B88-41D4-AF56-77B66B324640/Test.app/Test
Expected in: /System/Library/Frameworks/UIKit.framework/UIKit in /var/mobile/Applications/9770ACFA-0B88-41D4-AF56-77B66B324640/Test.app/TEST
As the App is built programmatically rather than using XIB's, I've split the 2 device logics using the following lines in the main.m method:
由于应用程序是以编程方式构建的,而不是使用 XIB,因此我在 main.m 方法中使用以下几行拆分了 2 个设备逻辑:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate_Pad");
}
else
{
retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate_Phone");
}
From that point forth they use different AppDelegates and I've checked my headers to ensure the UISplitView is never used nor imported via the Phone logic.
从那时起,他们使用不同的 AppDelegates,我检查了我的标题以确保 UISplitView 从未使用或通过电话逻辑导入。
How do I avoid this error and is there a better way to split the universal logic paths in this programmatically-created app?
如何避免此错误,是否有更好的方法来拆分此以编程方式创建的应用程序中的通用逻辑路径?
回答by Brad Larson
That error is being triggered because you didn't weak-link the UIKit framework. The UIKit framework in iPhone OS 3.2 added the UISplitViewController, and if you link it in as normal your application will assume those symbols exist on 3.0, where they don't.
触发该错误是因为您没有对 UIKit 框架进行弱链接。iPhone OS 3.2 中的 UIKit 框架添加了 UISplitViewController,如果您像往常一样链接它,您的应用程序将假定这些符号存在于 3.0 中,而它们不存在。
To weak-link a framework, find your application target in Xcode, inspect it, and go to the General tab. At the bottom of that tab should be a list of frameworks, with a column for Type. Change the Type for UIKit from Required to Weak and rebuild your application. That should take care of the runtime errors.
要弱链接框架,请在 Xcode 中找到您的应用程序目标,检查它,然后转到“常规”选项卡。该选项卡的底部应该是一个框架列表,其中有一列是 Type。将 UIKit 的类型从必需更改为弱并重建您的应用程序。这应该处理运行时错误。
Your conditional logic is sound, but I tend to share an application delegate and do the interface-specific layout further down the line.
您的条件逻辑是合理的,但我倾向于共享一个应用程序委托,并进一步进行特定于界面的布局。
(Update: 12/21/2011) As of iOS 4.2, you should no longer need to weak link frameworks to prevent errors like this. As Marco Arment describes, if you build with iOS 4.2 or later and target down to iPhone OS 3.1+, individual classes are now weak linked and should have their +class
method return nil
if the class does not exist on the currently running version of the OS.
(更新:12/21/2011)从 iOS 4.2 开始,您不再需要弱链接框架来防止此类错误。正如Marco Arment 所描述的那样,如果您使用 iOS 4.2 或更高版本构建并面向 iPhone OS 3.1+,则各个类现在是弱链接,如果当前运行的操作系统版本上不存在该类,则应+class
返回其方法nil
。
回答by xoconoxtle
I was having a very similar error and it was driving me nuts! :-) Searching for hours and couldn't figure it out...
我有一个非常相似的错误,它让我发疯!:-) 搜索了几个小时,还是想不通......
Like you said, everything was fine when running in the iPad Simulator but when trying to test the App on the iPhone with iPhone OS 3.1.2 it would not even start but crash with the following error message:
就像你说的,在 iPad Simulator 中运行时一切正常,但是当尝试在 iPhone OS 3.1.2 上测试应用程序时,它甚至无法启动,而是崩溃并显示以下错误消息:
mi_cmd_stack_list_frames not enough frames in stack
mi_cmd_stack_list_frames 堆栈中没有足够的帧
By checking nearly every line of code I realised that the allocating of 3.2 classes like UIPopoverController or UISplitViewController (already inside forked iPad-specific code) was causing the problem.
通过检查几乎每一行代码,我意识到分配 3.2 类,如 UIPopoverController 或 UISplitViewController(已经在分叉的 iPad 特定代码中)导致了问题。
So instead of i.e.:
所以而不是即:
infoPopover = [[UIPopoverController alloc] initWithContentViewController: infoNavController];
infoPopover = [[UIPopoverController alloc] initWithContentViewController: infoNavController];
i would write
我会写
infoPopover = [[NSClassFromString(@"UIPopoverController") alloc] initWithContentViewController: infoNavController];
infoPopover = [[NSClassFromString(@"UIPopoverController") alloc] initWithContentViewController: infoNavController];
and that solved my problem! (Debugging can be so hard if the error message gives you no clue about where the bug could possibly be found...)
这解决了我的问题!(如果错误消息让您不知道可能在哪里找到错误,则调试可能会非常困难......)
回答by CousinCocaine
Xcode 8.3, iPad 2 (non retina), Swift 3 code
Xcode 8.3、iPad 2(非视网膜)、Swift 3 代码
What helped for me was:
对我有帮助的是:
- restart Xcode
- do a 'Product -> Clean' ShiftCommandK
- rebuild the project
- 重启Xcode
- 做一个“产品 - >清洁” ShiftCommandK
- 重建项目