2011-12-18 26 views
15

Tôi đang tạo một ứng dụng iOS hiển thị bộ hẹn giờ. Tôi không nghĩ rằng tôi có thể giữ cho bộ đếm thời gian chạy sau khi người dùng nhấn nút home, vì vậy tôi muốn ghi lại thời gian khi người dùng thoát ứng dụng và sử dụng thời gian khi họ nhập lại ứng dụng để cập nhật bộ hẹn giờ. Đây là mã tôi đã cố gắng:Biểu tượng không xác định cho lỗi biên dịch i386 kiến ​​trúc do CACurrentMediaTime()

- (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. 
    */ 
} 

(nếu tôi nhận xét ra khỏi cơ thể phương pháp applicationWillResignActive nó xây dựng tốt)

Đây là lỗi tôi nhận được vào biên dịch

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)

Tôi nghĩ lỗi liên quan đến việc không nhập đúng khung, vì vậy tôi đã thử nhập

#import <QuartzCore/CoreAnimation.h> 

vào tệp tiêu đề AppDelegate của tôi, nhưng điều này cũng không hoạt động.

Tôi đang sử dụng CACurrentMediaTime() vì từ những gì tôi đã đọc, NSDate phụ thuộc vào mạng và do đó sẽ không từ bỏ các khoảng thời gian chính xác vì nó đã được sử dụng lần cuối

Trả lời

31

Bạn cần liên kết QuartzCore.framework. Đó là nơi CACurrentMediaTime đến từ: http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/CoreAnimation_functions/Reference/reference.html

Xem tài liệu này về cách thêm khung: https://developer.apple.com/library/ios/#recipes/xcode_help-project_editor/Articles/AddingaLibrarytoaTarget.html#//apple_ref/doc/uid/TP40010155-CH17-SW1

chỉnh sửa: Để làm rõ, trong khi bạn là chính xác trong cần phải bao gồm/nhập khẩu QuartzCore, bạn cũng cần phải liên kết chống lại nó, có liên quan, nhưng khác nhau. Xem Compiling and Linking

4

Chỉ cần thêm QuartzCore.framework đã giải quyết.

Các vấn đề liên quan