我試圖用ASIHTTPRequest
替換我的NSMutableURLRequest
,我嘗試了下面的內容,但是當我嘗試這個時,我的應用崩潰了。我沒有得到任何錯誤,只是一個警告:objective-c用ASIHTTPRequest替換NSMutableURLRequest
不兼容的指針類型發送「ASIHTTPRequest *」到類型的參數「的NSURLRequest *」
我該如何解決這個問題,我的嘗試下面是我有註釋掉了我的更換:
receivedData = [[NSMutableData alloc]init];
//NSURL *JSONURL = [NSURL URLWithString:url];
NSURL *url = [NSURL URLWithString:url];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setUseSessionPersistence:YES];
[request setUseKeychainPersistence:NO];
[request setUsername:@"username"];
[request setPassword:@"password"];
[request setDomain:@"domain"];
[request startSynchronous];
//NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:JSONURL];
jobsConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[jobsConnection start];
額外的代碼:
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
[receivedData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
//NSLog(@"%@" , error);
communityDictionary = nil;
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *myError;
if([connection isEqual:jobsConnection])
{
communityDictionary = [[NSDictionary alloc]initWithDictionary:
[NSJSONSerialization JSONObjectWithData:receivedData options:kNilOptions error:&myError]];
}
}
真的,你打算使用[dead library](http://allseeing-i.com/ [request_release];)嗎? – 2015-04-04 02:22:14
我不鼓勵你使用'ASIHTTPRequest'。如果你想使用第三方庫,現在很多人都傾向於[AFNetworking](https://github.com/AFNetworking/AFNetworking)。 – Rob 2015-04-04 02:33:26
這是一個可怕的決定....認真。我也勸阻AFNetworking順便說一句....沉重打擊它,但這個特定的圖書館是一個沒有腦子不使用。 – TheCodingArt 2015-04-06 02:26:20