我试图用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