0

我已经使用 SimplePost 类好几个星期了,没有遇到任何问题。现在,在请求在连接中返回正确数据后,我崩溃了。我没有(故意)接触过 SimplePost 类文件。但是当我运行分析器时,它现在(以前从未这样做过)指出了以下方法:

+ (NSMutableURLRequest *) urlencodedRequestWithURL:(NSURL *)url andDataDictionary:(NSDictionary *) dictionary {
   //  Create POST request
   NSMutableURLRequest *urlencodedPostRequest = [NSMutableURLRequest requestWithURL:url];
   [urlencodedPostRequest setHTTPMethod:@"POST"];
   //  Add HTTP header info
   [urlencodedPostRequest addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField: @"Content-Type"];
   //  Add POST body
   NSMutableData *POSTBody = [NSMutableData data];
   //  Add k/v to the body
   NSArray *keyArray = [dictionary allKeys];
   for( int i = 0; i < [keyArray count]; ++i ) {
       // Core Foundation function used to transform @ ==> %40 , etc
       NSString *escapedString = (__bridge NSString *) CFURLCreateStringByAddingPercentEscapes(NULL, (__bridge CFStringRef)([dictionary objectForKey:[keyArray objectAtIndex:i]]),NULL, (CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8);
       [POSTBody appendData:[[NSString stringWithFormat:@"%@=%@", [keyArray objectAtIndex:i], escapedString] dataUsingEncoding:NSUTF8StringEncoding]];
       if( i < ([keyArray count] - 1) ) {
            [POSTBody appendData:[[NSString stringWithFormat:@"&"] dataUsingEncoding:NSUTF8StringEncoding]];
       }
   }
   [urlencodedPostRequest setHTTPBody:POSTBody];
   return urlencodedPostRequest;
}

运行分析器向我显示:

错误 prt1
这些行继续为: 错误 prt2

我很难理解发生了什么。有人可以帮忙吗?谢谢!

4

1 回答 1

0

你试过__bridge_transferforescapedString吗?

   NSString *escapedString = (__bridge_transfer NSString *) CFURLCreateStringByAddingPercentEscapes(NULL, (__bridge CFStringRef)([dictionary objectForKey:[keyArray objectAtIndex:i]]),NULL, (CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8);

参看。ARC的正确桥接?

于 2012-12-05T15:23:27.987 回答