sendsynchronousRequestは、「許可しない」場所を「許可しない」後、3.1.2未満で失敗します
-
13-09-2019 - |
質問
私は行うことに問題があります sendSynchronousRequest
失敗。現在のジオロケーションを取得しようとし、ユーザーが「許可しない」とヒットした後にのみ失敗します。そして、それは3.1.2の下でのみ起こります。 (私が知る限り。3.0.1で正常に機能します。)
これが私がしていることです:
私は非常に基本的なテストアプリを設定しましたが、それにはほとんど何もありません。の applicationDidFinishLaunching
私は自分の関数、テストに電話を追加します。
- (void) test
{
CLLocationManager *mLM;
mLM = [[CLLocationManager alloc] init];
mLM.delegate = self;
if ( [mLM locationServicesEnabled] )
{
[mLM startUpdatingLocation];
}
}
私の代表的な方法も非常に簡単です:
- (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
}
最後に、これが私の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;
NSData *respdata = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
[request release];
}
通話 sendSynchronousRequest
吊るします。これは非常にイライラしています。誰かがアイデアを持っていますか?
解決
これは魔法です。 MLMがクラスのバラルブルであることを確認してください。これを使用できます。
- (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!!!
}
所属していません StackOverflow