applicationWillResignActive

applicationWillResignActive

本文介绍了由CACurrentMediaTime()引起的体系结构i386编译错误的未定义符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

(如果我注释掉applicationWillResignActive方法体,它建立正常)

(if I comment out the applicationWillResignActive method body it builds fine)

这是我在编译时遇到的错误

This is the error I'm getting on compile

有关i386硬件架构未定义的符号:
_CACurrentMediaTime,引自:
- [ImpromptuTimerAppDelegate applicationWillResignActive:] in ImpromptuTimerAppDelegate.o
ld:找不到架构i386的符号
clang:错误:链接器命令失败,退出代码为1(使用-v查看调用)

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>

进入我的AppDelegate头文件,但这也不起作用。

into my my AppDelegate header file, but this did not work either.

我正在使用CACurrentMediaTime(),因为根据我的阅读,NSDate依赖于网络,因此自上次使用以来不会给出准确的时间间隔

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

推荐答案

您需要链接QuartzCore.framework。
这就是CACurrentMediaTime的来源:

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

编辑:为了澄清,虽然您需要包含/导入QuartzCore是正确的,但您还需要链接它,这是相关的,但不同。请参阅

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

这篇关于由CACurrentMediaTime()引起的体系结构i386编译错误的未定义符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 06:21