如何在我的应用程序中获取CLLocationManager

时间:2022-01-28 16:55:23
@class CLLocationManager;

@interface CLLocationController : NSObject 
{ 
   CLLocationManager *locationManager; 
}

@property (nonatomic, retain) CLLocationManager *locationManager;

@end

When i write above code is shows me following errors

当我写上面代码时显示我跟随错误

error: CLLocationManager.h: No such file or directory warning: receiver 'CLLocationManager' is a forward class and corresponding @interface may not error: accessing unknown 'delegate' component of a property

错误:CLLocationManager.h:没有这样的文件或目录警告:接收者'CLLocationManager'是一个转发类,相应的@interface可能没有错误:访问属性的未知'委托'组件

2 个解决方案

#1


18  

Why are you declaring your own classes with the CL prefix?

你为什么用CL前缀声明自己的类?

Also, the error has nothing to do with the code you showed; it refers to the #import line in your implementation file. You're probably doing something like this:

此外,错误与您显示的代码无关;它指的是实现文件中的#import行。你可能正在做这样的事情:

#import "CLLocationManager.h"

instead of the correct way:

而不是正确的方式:

#import <CoreLocation/CoreLocation.h>

Don't import individual headers from a framework directly—import its top-level header and let that give you what you need. If compilation is getting to take too long, move the #import to your prefix header and make sure you have “Precompile Prefix Header” turned on.

不要直接从框架导入单个标题 - 导入其*标题,然后让它为您提供所需的标题。如果编译时间过长,请将#import移动到前缀标头,并确保已打开“预编译前缀标题”。

#2


6  

Also, don't forget you have to actually add the CoreLocation framework to your app. To do this, double click on your target, go to the first tab, and click the + button in the lower left. This will bring up a list of available frameworks. Find CoreLocation.framework, and click "OK".

另外,不要忘记您必须将CoreLocation框架实际添加到您的应用程序中。要执行此操作,请双击目标,转到第一个选项卡,然后单击左下方的+按钮。这将显示可用框架的列表。找到CoreLocation.framework,然后单击“确定”。

#1


18  

Why are you declaring your own classes with the CL prefix?

你为什么用CL前缀声明自己的类?

Also, the error has nothing to do with the code you showed; it refers to the #import line in your implementation file. You're probably doing something like this:

此外,错误与您显示的代码无关;它指的是实现文件中的#import行。你可能正在做这样的事情:

#import "CLLocationManager.h"

instead of the correct way:

而不是正确的方式:

#import <CoreLocation/CoreLocation.h>

Don't import individual headers from a framework directly—import its top-level header and let that give you what you need. If compilation is getting to take too long, move the #import to your prefix header and make sure you have “Precompile Prefix Header” turned on.

不要直接从框架导入单个标题 - 导入其*标题,然后让它为您提供所需的标题。如果编译时间过长,请将#import移动到前缀标头,并确保已打开“预编译前缀标题”。

#2


6  

Also, don't forget you have to actually add the CoreLocation framework to your app. To do this, double click on your target, go to the first tab, and click the + button in the lower left. This will bring up a list of available frameworks. Find CoreLocation.framework, and click "OK".

另外,不要忘记您必须将CoreLocation框架实际添加到您的应用程序中。要执行此操作,请双击目标,转到第一个选项卡,然后单击左下方的+按钮。这将显示可用框架的列表。找到CoreLocation.framework,然后单击“确定”。