How to fix setAllowsAnyHTTPSCertificate private api use for Apple app submission?

♀尐吖头ヾ 提交于 2019-12-12 21:12:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!