我正在尝试使用XCODE在iOS中为GPS构建一个库,但它不能用作库,我在客户端应用程序中使用时不调用didUpdateToLocation
,但它作为应用程序正常运行。我没有得到我犯错的地方。
这是我的应用程序端代码,我已导入库代码
- (void)viewDidLoad
{
[super viewDidLoad];
LocLibrary *mFunctions = [[LocLibrary alloc] init];//Creating a object
[mFunctions startGps];// Calling library method
}
以下是我的LocLibrary.h
@interface LocLibrary : NSObject <CLLocationManagerDelegate>
{
CLLocationManager *locMgr;
int latitude,longitude;
}
-(void)startGps;
@property (strong, nonatomic) CLLocationManager *locMgr;
@property (strong, nonatomic) CLLocation *currentLocation;
@end
以下是LocLibarry.m代码,didUpdateLocation
方法无法正常工作
-(void)startGps
{
NSLog(@"getGps");
locMgr = [[CLLocationManager alloc] init];
NSLog(@"getGps1");
locMgr.delegate = self;
locMgr.distanceFilter=kCLDistanceFilterNone;
locMgr.desiredAccuracy = kCLLocationAccuracyBest;
[locMgr startUpdatingLocation];//Upto this working, it is not calling below code
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { //This method not working
self.currentLocation = newLocation;
NSLog(@"Success");
if(newLocation.horizontalAccuracy <= 100.0f)
{
[locMgr stopUpdatingLocation];
NSLog(@"Stopped");
}
}
答案 0 :(得分:0)
检查您正在创建viewDidLoad
对象的LocLibrary2
方法中的以下行,并将其分配给LocLibrary
。
LocLibrary *mFunctions = [[LocLibrary2 alloc] init];//Creating a object