xcode PhoneGap 应用程序的 iPad 测试 - 主要方法中的问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7006593/
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
iPad testing of PhoneGap application - issues in main method
提问by Ben Potter
So I was attempting to test a PhoneGapapplication I've been working on, and had some issues with the test on my iPad. I have the following as the main
method for this application:
因此,我试图测试我一直在开发的PhoneGap应用程序,但在 iPad 上的测试中遇到了一些问题。我有以下作为main
此应用程序的方法:
//
// main.m
// elog
//
// Created by Ben Potter on 9/08/11.
// Copyright Arden Anglican School 2011. All rights reserved.
//
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate");
[pool release];
return retVal;
}
It all works fine until you close the app completely and then reopen it, upon which it freezes. And I have no idea why.
一切正常,直到您完全关闭应用程序然后重新打开它,然后它就会冻结。我不知道为什么。
I am running ios5 on my ipad with XCode 4.2
我正在使用 XCode 4.2 在 ipad 上运行 ios5
Finally, these are the errors which come up, thanks for the help!
最后,这些是出现的错误,感谢您的帮助!
回答by dtuckernet
Your application is using Automatic Reference Counting (which is new) and Phonegap doesn't support it yet. Go to your project's build settings and turn Automatic Reference Counting to off.
您的应用程序正在使用自动引用计数(这是新的),Phonegap 尚不支持它。转到项目的构建设置并关闭自动引用计数。
回答by Nicklas Savonen
This is how I solved the "NSAutoReleasePool" error in XCode 4.3 and with PhoneGap 1.5.
这就是我在 XCode 4.3 和 PhoneGap 1.5 中解决“NSAutoReleasePool”错误的方法。
Go to "YourApplicationName" in the Project Navigator.
Select "YourApplicationName" under Project.
Go to Build Settings.
Make sure to toggle "All" and "Combined".
Find the section "Apple LLVM compiler 3.1 - Language".
Scroll down and you will find "Objective-C Automatic Reference Counting".
Change it from Yes to No.
转到项目导航器中的“YourApplicationName”。
在项目下选择“YourApplicationName”。
转到构建设置。
确保切换“全部”和“组合”。
找到“Apple LLVM 编译器 3.1 - 语言”部分。
向下滚动,您会发现“Objective-C 自动引用计数”。
将其从是更改为否。
Try to build your project again and you should be fine!
尝试再次构建您的项目,您应该没问题!
回答by Brian Moeskau
So, just to clarify for the visually-inclined, it took me a few minutes to find the correct option since it's only mentioned in the comments of another answer. I had to find the CLANG_ENABLE_OBJC_ARC
build flag and switch it to NO
. You'll find it under the Build settings in the User-Defined section (very bottom for me):
所以,为了澄清视觉上的倾向,我花了几分钟才找到正确的选项,因为它只在另一个答案的评论中提到。我必须找到CLANG_ENABLE_OBJC_ARC
构建标志并将其切换到NO
. 您可以在 User-Defined 部分的 Build 设置下找到它(对我来说非常底部):
I was also able to get past the runtime error by going into main.m
and commenting out the NSAutoreleasePool
setup code like so:
我还可以通过进入main.m
并注释掉NSAutoreleasePool
设置代码来解决运行时错误,如下所示:
//NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate");
//[pool release];
return retVal;
However, I'm not sure what other effects that might have down the line. It seems that at present, while working with PhoneGap, it's probably best to stick with manual ref counting until PhoneGap properly supports ARC.
但是,我不确定可能会产生哪些其他影响。目前看来,在使用 PhoneGap 时,最好坚持手动引用计数,直到 PhoneGap 正确支持 ARC。
And just for Google, the error that led me here was "NSAutoreleasePool is unavailable" as I don't see that as text in the original post.
就 Google 而言,导致我来到这里的错误是“NSAutoreleasePool 不可用”,因为我在原始帖子中没有将其视为文本。
回答by iOSAndroidWindowsMobileAppsDev
Prior to cordova 2.1.0 ARC is not supported, you are not supposed tick the box below (when you are still creating your project):
在cordova 2.1.0 ARC 不支持之前,你不应该勾选下面的框(当你还在创建你的项目时):
However, this is the exact code you need:
但是,这是您需要的确切代码:
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
@autoreleasepool {
int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate");
return retVal;
}
}
If you upgrade to cordova 2.1.0 in Xcode 4.5.1 you can go to:
Edit
Refactor
The choose between Objective ARC and Modern Objective-C syntax.
如果您在 Xcode 4.5.1 中升级到cordova 2.1.0,您可以转到:编辑重构Objective ARC 和Modern Objective-C 语法之间的选择。
回答by Hyman
If you don't want to disable ARC, then the following will fix the errors in Xcode 4.2.
如果您不想禁用 ARC,那么以下内容将修复 Xcode 4.2 中的错误。
AppDelegate.m
AppDelegate.m
// self.window = [[[UIWindow alloc] initWithFrame:screenBounds]autorelease];
self.window = [[UIWindow alloc] initWithFrame:screenBounds];
// self.viewController = [[[MainViewController alloc] init] autorelease];
self.viewController = [[MainViewController alloc] init];
(void) dealloc
{
// [super dealloc];
}
main.m
主文件
int main(int argc, char *argv[]) {
// NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate");
// [pool release];
// return retVal;
@autoreleasepool {
NSLog (@"Programming is fun!");
}
return 0;
}
Disclaimer:
免责声明:
Not sure how this affects the rest of the PhoneGap lib an plugins though. However, after implementing these changes, the template PhoneGap project runs on the simulator, but terminates instantly. This was just a starting point.
不确定这如何影响 PhoneGap lib 和插件的其余部分。但是,在实施这些更改后,模板 PhoneGap 项目会在模拟器上运行,但会立即终止。这只是一个起点。
Better Alternative:
更好的选择:
I suggest you disable Automatic Reference Counting (ARC) under Build Settings until PhoneGap supports it. This thread on on PhoneGap forum hints that ARC may be supported in PhoneGap 1.6.
我建议您在构建设置下禁用自动引用计数 (ARC),直到 PhoneGap 支持它。PhoneGap 论坛上的这个主题暗示PhoneGap 1.6 可能支持 ARC。