Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 带ASITPPREQUEST的ARC_Iphone_Ios_Automatic Ref Counting - Fatal编程技术网

Iphone 带ASITPPREQUEST的ARC

Iphone 带ASITPPREQUEST的ARC,iphone,ios,automatic-ref-counting,Iphone,Ios,Automatic Ref Counting,我正在使用iOSSDK5开发应用程序,我正在尝试使用ARC。但是我需要使用ASIHTTPRequest,并且它没有启用ARC。苹果的医生说可以使用基于ARC文件的。因此,我使用-fno objc arc编译所有ASIHTTPRequest文件。我在我的类中使用ARC编写以下代码: NSURL *url = [[NSURL alloc] initWithString:urlStr]; ASIHTTPRequest *req = [[ASIHTTPRequest alloc] initWithURL

我正在使用iOSSDK5开发应用程序,我正在尝试使用ARC。但是我需要使用
ASIHTTPRequest
,并且它没有启用ARC。苹果的医生说可以使用基于ARC文件的。因此,我使用
-fno objc arc
编译所有
ASIHTTPRequest
文件。我在我的类中使用ARC编写以下代码:

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

但在执行第一行之后,url为零。ARC项目中有什么错误或如何使用手动管理的代码?谢谢。

您是否已转义URL字符串中的所有非ASCII字符?如果没有,则不会创建NSURL实例,因为它不知道如何处理URL字符串中的非ASCII字符。您需要这样做:

NSURL *url = [NSURL URLWithString:[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
另外,与其创建自己的NSURL实例,不如使用Apple的helper方法
URLWithString:
,它将为您提供一个“自动删除”的NSURL实例,如下所示:

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

是的,我忘了逃跑。谢谢。如果使用ARC,那么使用alloc/init比使用自动释放方法更节省时间和空间。差别通常不大,但有时每一个小的帮助。IOS5仍然被NDA覆盖,所以知道它的人在没有与苹果达成协议的情况下无法回答。话虽如此,我认为这与ARC或iOS5无关。