2011-12-18 68 views
15

我在製作一個iOS應用程序來顯示一個計時器。我不認爲我可以在用戶按下主頁按鈕後繼續運行計時器,因此我想記錄用戶退出應用程序的時間,並使用重新進入應用程序更新計時器的時間。這是我試過的代碼:由CACurrentMediaTime引起的架構i386編譯錯誤的未定義符號()

- (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方法體)

這是我得到的編譯

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/Objects-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/Max/Library/Developer/Xcode/DerivedData/ImpromptuTimer-cbcnsujnixygrxfhtvkovhnpqamb/Build/Products/Debug-iphonesimulator/ImpromptuTimer.app/ImpromptuTimer

Undefined symbols for architecture i386: "_CACurrentMediaTime", referenced from: -[ImpromptuTimerAppDelegate applicationWillResignActive:] in ImpromptuTimerAppDelegate.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)

我認爲錯誤錯誤與不導入正確的框架有關,所以我嘗試導入

#import <QuartzCore/CoreAnimation.h> 

進入我的AppDelegate頭文件,但這也不起作用。

我使用CACurrentMediaTime(),因爲從我讀過,NSDate的是依賴於網絡,因此,因爲它是最後一次使用

回答

31

您需要關聯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正確的,你還需要對鏈接它是相關的,但不同的。見Compiling and Linking

4

簡單地添加QuartzCore.framework解決了它。

相關問題