Crashing on unrecognized selector sent with Simple

2019-08-31 04:14发布

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;
}

And running the Analyzer shows me:

bug prt1
the lines continue as: bug prt2

I'm having a hard time understanding what's happening. Can anyone help, please? Thanks!

1条回答
干净又极端
2楼-- · 2019-08-31 05:04

Have you tried the __bridge_transfer for escapedString?

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

cf. Correct bridging for ARC?

查看更多
登录 后发表回答