由CACurrentMediaTime()引起的架构i386编译错误的未定义符号

我正在做一个iOS应用程序显示一个计时器。 我不认为我可以让用户按下主页button后保持定时器运行,所以我想logging用户退出应用程序的时间,并使用重新进入应用程序更新定时器的时间。 这是我试过的代码:

- (void)applicationWillResignActive:(UIApplication *)application { double currentTime = CACurrentMediaTime(); NSLog(@"%g", currentTime); /* Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. */ } 

(如果我注释掉applicationWillResignActive方法体,它build立的很好)

这是我正在编译的错误

Ld /Users/Max/Library/Developer/Xcode/DerivedData/ImpromptuTimer-cbcnsujnixygrxfhtvkovhnpqamb/Build/Products/Debug-iphonesimulator/ImpromptuTimer.app/ImpromptuTimer normal i386 cd / Users / Max / Developer / ImpromptuTimer setenv MACOSX_DEPLOYMENT_TARGET 10.6 setenv PATH“/ Developer /Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin“/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin / clang -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -L / Users / Max / Library / Developer / Xcode / DerivedData / ImpromptuTimer -cbcnsujnixygrxfhtvkovhnpqamb / Build / Products / Debug- iphonesimulator -F / Users / Max / Library / Developer / Xcode / DerivedData / ImpromptuTimer -cbcnsujnixygrxfhtvkovhnpqamb / Build / Products / Debug-iphonesimulator -filelist / Users / Max / Library / Developer / Xcode / DerivedData / ImpromptuTimer -cbcnsujnixygrxfhtvkovhnpqamb / Build / Intermediates / ImpromptuTimer.build/Debug-iphonesimulator/ImpromptuTimer.build/ 对象-normal / i386 / ImpromptuTimer.LinkFileList -mmacosx-version-min = 10.6 -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -Xlinker -no_implicit_dylibs -D__IPHONE_OS_VERSION_MIN_REQUIRED = 50000 -framework UIKit -framework Foundation -framework CoreGraphics -o / Users /最大/库/开发商/ Xcode中/ DerivedData / ImpromptuTimer-cbcnsujnixygrxfhtvkovhnpqamb /编译/产品/debugging-iphonesimulator / ImpromptuTimer.app / ImpromptuTimer

未定义的符号体系结构i386:“_CACurrentMediaTime”,引用自: – ImpromptuTimerAppDelegate.o中的[ImpromptuTimerAppDelegate applicationWillResignActive:] ld:体系结构i386中未find符号clang:error:链接器命令失败,退出代码1(使用-v请参阅调用)

我认为这个错误是关于不导入正确的框架,所以我试图导入

 #import <QuartzCore/CoreAnimation.h> 

进入我的AppDelegate头文件,但这也没有工作。

我正在使用CACurrentMediaTime(),因为从我读过,NSDate是依赖于networking,因此不会给出自上次使用以来的准确时间间隔

你需要链接QuartzCore.framework。 这就是CACurrentMediaTime的来源: http : //developer.apple.com/library/ios/#documentation/Cocoa/Reference/CoreAnimation_functions/Reference/reference.html

关于如何添加框架,请参阅此文档: https : //developer.apple.com/library/ios/#recipes/xcode_help-project_editor/Articles/AddingaLibrarytoaTarget.html#//apple_ref/doc/uid/TP40010155-CH17-SW1

编辑:为了澄清,当你需要包含/导入QuartzCore是正确的,你也需要链接它,这是相关的,但不同的。 请参阅编译和链接

简单地添加QuartzCore.framework解决了它。