Alternative method for NSURLRequest's private “setAllowsAnyHTTPSCertificate:forHost:”?

前端 未结 5 1125
遥遥无期
遥遥无期 2020-12-30 03:41

My iPhone application was rejected solely for using the (very safe, it seems) private method +setAllowsAnyHTTPSCertificate:forHost: for NSURLRequest. Is there a

5条回答
  •  無奈伤痛
    2020-12-30 03:47

    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.

提交回复
热议问题