我对objective-c很陌生,但我正在尝试尽可能多地学习。
我需要在静态类中调用 CLLocationManager。我一直在谷歌搜索,但我不明白如何设置委托。因为这是一个静态类,我假设我需要创建一个新类并通过它。
静态类:
PositionManager *positionManage = [[PositionManager alloc] init];
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:positionManage];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
位置管理器.h
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
@interface PositionManager : NSObject <CLLocationManagerDelegate> {
CLLocationManager *locationManager;
}
@property (strong, retain) CLLocationManager *locationManager;
@end
位置管理器.m
#import "PositionManager.h"
@implementation PositionManager
@synthesize locationManager;
- (id)init {
self = [super init];
NSLog(@"hei?");
return self;
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
// Never gets called...
}
@end