Bir*_*chi 12 iphone core-location cllocationmanager cllocation
这是我在AppDelegate类中的代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = 1000; // 1 Km
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
[locationManager startUpdatingLocation];
}
Run Code Online (Sandbox Code Playgroud)
这是我在AppDelegate类中的委托方法
//This is the delegate method for CoreLocation
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
//printf("AppDelegate latitude %+.6f, longitude %+.6f\n", newLocation.coordinate.latitude, newLocation.coordinate.longitude);
}
Run Code Online (Sandbox Code Playgroud)
它工作在3.0,3.1,3.1.3,但它不适用于4.0模拟器和设备.
是什么原因 ?
Seb*_*iew 21
我有类似的错误,现在解决了.问题是在本地声明locationManager变量.将其声明为类变量,并确保直接或通过属性保留(如果使用ARC则保持强大).这解决了问题!问题是de locationManager变量已发布,并且从未更新过委托.这里的代码:
.h文件:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
@interface MapViewController : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate> {
@private
MKMapView *_mapView;
CLLocationManager *_locationManager;
}
@property(nonatomic, strong) CLLocationManager *locationManager;
@end
Run Code Online (Sandbox Code Playgroud)
.m文件:
self.locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[_locationManager startUpdatingLocation];
Run Code Online (Sandbox Code Playgroud)
我希望它有所帮助.
归档时间: |
|
查看次数: |
15558 次 |
最近记录: |