I'm making an iOS application displaying a timer. I don't think I can keep the timer running after the user presses the home button, so I want to record the time when the user quits the app, and use the time when they reenter the app to update the timer. This is the code I tried:
- (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.
*/
}
(if I comment out the applicationWillResignActive method body it builds fine)
This is the error I'm getting on compile
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)
I think the error is related to not importing the right frameworks, so I tried importing
#import <QuartzCore/CoreAnimation.h>
into my my AppDelegate header file, but this did not work either.
I'm using CACurrentMediaTime() because from what I've read, NSDate is dependent on the network and thus will not give accurate time intervals since it was last used
You need to link QuartzCore.framework. That's where CACurrentMediaTime comes from: http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/CoreAnimation_functions/Reference/reference.html
See this document on how to add frameworks: https://developer.apple.com/library/ios/#recipes/xcode_help-project_editor/Articles/AddingaLibrarytoaTarget.html#//apple_ref/doc/uid/TP40010155-CH17-SW1
edit: To clarify, while you are correct in needing to include/import QuartzCore, you also need to link against it, which is related, but different. See Compiling and Linking
Simply Adding QuartzCore.framework solved it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With