问题
I'm using the following code to send a user login to a server, but Apple says that I'm using a private API and will reject the app. How can I resolve this?
would replacing with [NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
[request setHTTPMethod:@"POST"];
be enough?
@interface NSURLRequest (DummyInterface)
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString*)host;
+ (void)setAllowsAnyHTTPSCertificate:(BOOL)allow forHost:(NSString*)host;
@end
and my login code:
// token url
NSURL *url=[NSURL URLWithString:@"http://xxxxxxxx.com/api/token"];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSLog(@"url is %@",url),
NSLog(@"request is %@",request),
**[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];**
回答1:
There seems to be a public API for that.
How to use NSURLConnection to connect with SSL for an untrusted cert?
Must be late but might help.
来源:https://stackoverflow.com/questions/19276373/how-to-fix-setallowsanyhttpscertificate-private-api-use-for-apple-app-submission