sendSynchronousRequest fails under 3.1.2 after "Don't Allow" location fetch
I'm having a problem with doing a sendSynchronousRequest
failing. It only fails after I try to get the current geolocation and the user hits "Don't Allow". And it only happens under 3.1.2. (As far as I can tell. It works fine in 3.0.1.)
Here's what I do:
I set up a very basic test app, that has almost nothing in it. In applicationDidFinishLaunching
I add a call to my function, test, which is here:
- (void) test
{
CLLocationManager *mLM;
mLM = [[CLLocationManager alloc] init];
mLM.delegate = self;
if ( [mLM locationServicesEnabled] )
{
[mLM startUpdatingLocation];
}
}
My delegate methods are pretty simple too:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
[manager stopUpdatingLocation];
[self sendRequest]; // succeeds
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
[manager stopUpdatingLocation];
[self sendRequest]; // fails
}
Finally, here's my sendRequest:
- (void) sendRequest
{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"https://theurl"]]; // this is actually a valid URL, changed here for privacy
[request setHTTPMethod:@"GET"];
[request setCachePolicy:NSURLRequestReloadIgnoringCacheData];
NSString *unpw = @"username:password";
NSString *base64 = [NSString base64StringFromString:unpw];
[request addValue:[NSString stringWithFormat:@"Basic %@", base64] forHTTPHeaderField:@"Authorization"];
NSURLResponse *response = nil;
NSError *error = nil;
NSDa开发者_运维百科ta *respdata = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
[request release];
}
The call to sendSynchronousRequest
hangs. This has been very frustrating. Does anyone have any ideas?
This will work it's magic. Make sure the mLm is your class varialble, so you can to this:
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
[self.mLm release];
self.mLM = [[CLLocationManager alloc] init];
self.mLM.delegate = nil;
[self sendRequest]; // fails - This time it will work!!!
}
精彩评论