gpt4 book ai didi

objective-c - 未调用 CLLocationManager 委托(delegate)

转载 作者:可可西里 更新时间:2023-11-01 17:02:19 24 4
gpt4 key购买 nike

<分区>

我在设备上使用 CLLocationManager 并且没有调用委托(delegate)方法。这是我的代码(我可以看到该类也没有被释放):

#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>

@interface CurrentLocation : NSObject <CLLocationManagerDelegate> {
CLLocationManager *locationManager;

}
@property (nonatomic, retain) CLLocationManager *locationManager;

@end

#import "CurrentLocation.h"
#import "SBJson.h"
@implementation CurrentLocation
@synthesize locationManager;

- (id)init
{
self = [super init];
if (self) {
NSLog(@"Initialized");
locationManager = [[[CLLocationManager alloc] init] autorelease];
locationManager.delegate = self;
[locationManager startUpdatingLocation];
BOOL enable = [CLLocationManager locationServicesEnabled];
NSLog(@"%@", enable? @"Enabled" : @"Not Enabled");
}

return self;
}

- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
NSLog(@"A");
NSString *stringURL = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&sensor=true", newLocation.coordinate.latitude, newLocation.coordinate.longitude];
NSLog(@"%@", stringURL);

NSURL *url = [NSURL URLWithString:stringURL];

NSData *data = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:url] returningResponse:nil error:nil];

SBJsonParser *parser = [[SBJsonParser alloc] init];
NSDictionary *dict = [parser objectWithData:data];
NSLog(@"%@", dict);
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
NSLog(@"B");
}

- (void)dealloc {
NSLog(@"Dealloc called");
[super dealloc];
[locationManager release];
}

@end

在日志中,我看到:

2011-10-02 19:49:04.095 DixieMatTracker[1404:707] Initialized
2011-10-02 19:49:04.109 DixieMatTracker[1404:707] Enabled

我做错了什么?谢谢

24 4 0
文章推荐: php - 如何在 Objective C/iOS 中解密 PHP 脚本
文章推荐: javascript - 检查是否 spotify : url is available on user device
文章推荐: java - 如何进行服务器端 HTTP 重定向而不是元刷新
文章推荐: java - Jersey | List 到客户端 post/get/put 请求?