Alternative method for NSURLRequest's private

2019-02-04 10:42发布

My iPhone application was rejected solely for using the (very safe, it seems) private method +setAllowsAnyHTTPSCertificate:forHost: for NSURLRequest. Is there a non-private API to emulate this functionality?

6条回答
Summer. ? 凉城
2楼-- · 2019-02-04 11:08

Not a solution, but a suggestion. Have you thought about using ASIHttpRequest Framework for this? This framework is complete in all aspects. Check the documentation, maybe it can help you too.

查看更多
贼婆χ
3楼-- · 2019-02-04 11:13

Take a look at this link: http://www.abstractec.co.uk/blog/iPhone.php?itemid=70

Might be a better solution for you than just tricking the private API check.

查看更多
兄弟一词,经得起流年.
4楼-- · 2019-02-04 11:16

setAllowsAnyHTTPSCertificate seems to now be unsupported in OS X 10.6.6 altogether.

Did I say 10.6.6? Perhaps I should have said "Snow Vista".

查看更多
做个烂人
5楼-- · 2019-02-04 11:19

One really stupid workaround is to make your own category method:

@implementation NSURLRequest (IgnoreSSL)

+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host
{
    return YES;
}

@end

This should get by Apple's private API checks, but it's still the same thing (using a private, undocumented API[1] that is liable to break at any time). Actually, it's worse since it allows everything, not just that host.

[1]: An private API that should be made public, but a private API nevertheless.

查看更多
我欲成王,谁敢阻挡
6楼-- · 2019-02-04 11:22

Actually, I'm testing with 10.6.8 and this code still works -- it's using the private API but checking that the selector exists (myurl is the NSURL I'm trying to load into a WebView or an NSURLConnection):

SEL selx = NSSelectorFromString(@"setAllowsAnyHTTPSCertificate:forHost:");
if ( [NSURLRequest respondsToSelector: selx] )
{
    IMP fp;

    fp = [NSURLRequest methodForSelector:selx];

    (fp)([NSURLRequest class], selx, YES, [myurl host]);
}

Note that "@selector" wasn't used so that absolutely all the work would be done at runtime. That makes it about as safe and as hidden from Apple's checks as can be, especially if you obscure the string.

查看更多
疯言疯语
7楼-- · 2019-02-04 11:24
登录 后发表回答