成功运行后,随SimplePost请求发送的无法识别的选择器崩溃. [英] Crashing on unrecognized selector sent with SimplePost request after it works successfully.
本文介绍了成功运行后,随SimplePost请求发送的无法识别的选择器崩溃.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经使用SimplePost类数周了,没有任何问题.现在,当请求在Connection中返回正确的数据后,我崩溃了.我还没有(知道)接触过SimplePost类文件.但是,当我运行分析器时,它现在(从未做过)指出以下方法:
I've been using the SimplePost classes for several weeks and haven't had any problems. Now I'm crashing after a Request returns proper data in a Connection. I haven't (knowingly) touched the SimplePost class files. But when I run the analyzer, it now (never did before) points out the following method:
+ (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;
}
运行分析器会显示:
行继续为:
the lines continue as:
我很难理解正在发生的事情.有人可以帮忙吗?谢谢!
I'm having a hard time understanding what's happening. Can anyone help, please? Thanks!
推荐答案
您是否为escapedString
尝试了__bridge_transfer
?
NSString *escapedString = (__bridge_transfer NSString *) CFURLCreateStringByAddingPercentEscapes(NULL, (__bridge CFStringRef)([dictionary objectForKey:[keyArray objectAtIndex:i]]),NULL, (CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8);
cf. 是否为ARC正确桥接?
这篇关于成功运行后,随SimplePost请求发送的无法识别的选择器崩溃.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文