我對Objective-C很新,但我正在玩儘可能多的學習。CLLocationManager,代理沒有被調用
我需要在靜態類中調用CLLocationManager。我一直在徘徊,但我不明白如何設置代表。因爲這是一個靜態類,我認爲我需要創建一個新類並通過它。
靜態類:
PositionManager *positionManage = [[PositionManager alloc] init];
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:positionManage];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
PositionManager.h
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
@interface PositionManager : NSObject <CLLocationManagerDelegate> {
CLLocationManager *locationManager;
}
@property (strong, retain) CLLocationManager *locationManager;
@end
PositionManager.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
你也應該實現'的LocationManager:didFailWithError:'和檢查,看看是否被調用來代替。 – 2013-03-18 19:12:21
爲我工作。謝謝 – 2013-10-04 12:54:53