【发布时间】:2015-02-17 11:29:50
【问题描述】:
我有一个带有UIWebView 的简单objective C 应用程序。这是在 viewDidLoad 方法中加载一个 URL,我需要将此 URL 本地化 BEFORE loadRequest 但我的 CLLocationManager 正在调用 didUpdateToLocation 方法 AFTER loadRequest.
我的viewDidLoad 方法:
- (void)viewDidLoad {
// execute super method
[super viewDidLoad];
// put gray background color
self.view.backgroundColor = [UIColor lightGrayColor];
// define itself as UIWebView delegate
self.webView.delegate = self;
// define itself as CLLocationManager delegate
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
NSLog(@"LOCALIZED????%@",[self getCustomURL:homeURL]);
[self.webView loadRequest:[[NSURLRequest alloc] initWithURL:[NSURL URLWithString:[self getCustomURL:homeURL]]]];
}
我在调用loadRequest 时总是得到 (null),但在我得到正确的位置之后。
我试图在一个新线程中分离startUpdatingLocation
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[locationManager startUpdatingLocation];
});
或者等到找到正确的位置:
while (longitude == nil) {
[locationManager startUpdatingLocation];
}
知道如何获取loadRequest 之前的位置以获取网址
【问题讨论】:
标签: ios objective-c iphone xcode geolocation