开发者

ARC with ASIHTTPRequest

开发者 https://www.devze.com 2023-04-06 08:32 出处:网络
I\'m using iOS SDK 5 to develop apps and I\'m trying to use ARC. But I need to use ASIHTTPRequest and 开发者_如何学JAVAit\'s not ARC-enabled. Apple\'s doc said it\'s OK to use ARC file-based. So I com

I'm using iOS SDK 5 to develop apps and I'm trying to use ARC. But I need to use ASIHTTPRequest and 开发者_如何学JAVAit's not ARC-enabled. Apple's doc said it's OK to use ARC file-based. So I compile all ASIHTTPRequest files with -fno-objc-arc. I write the following code in my class, which is using ARC:

NSURL *url = [[NSURL alloc] initWithString:urlStr];
ASIHTTPRequest *req = [[ASIHTTPRequest alloc] initWithURL:url];
req.delegate = self;
[req startAsynchronous];

but after executing the first line, the url is nil. What's wrong or how to use manually managed code in ARC project? Thanks.


Have you escaped all the not ASCII characters in your URL String? If not, the NSURL instance isn't being created because it doesn't know how to handle the non-ASCII characters in your URL String. You'd need to do something like so:

NSURL *url = [NSURL URLWithString:[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

Also, Instead of creating your own instance of NSURL, why not use Apple's helper method URLWithString: which will give you an 'autoreleased' NSURL instance like so:

NSURL *url = [NSURL URLWithString:[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
ASIHTTPRequest *req = [[ASIHTTPRequest alloc] initWithURL:url];
req.delegate = self;
[req startAsynchronous];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号