简体   繁体   中英

On ios, in ionic hybrid app, how to bypass certificate check (using self-signed certificates)

My ionic/cordova app now gives errors when used with HTTPS backend

`The certificate for this server is invalid`

I am in my development environment, use self-signed certificates, and use IP address to connect with the backend.

I examined the certificate using openssl s_client and it looks valid. As a matter of fact I am able to use the same backend with android version of this hybrid app.

Is there some plist or other Xcode setting to accept a self-signed certificate or ignore this test all together - similar to NSAppTransportSecurity::NSAllowsArbitraryLoads setting?

--EDIT

I have <access origin="*"/> in my config.xml file.

Thanks a lot

You can add this at the end of AppDelegate.m, but just for testing purposes, you should remove it before releasing the app, apple might not approve the app if it contains that code

@implementation NSURLRequest(DataController)
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host
{
    return YES;
}
@end

Try adding this to info.plist

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSAllowsArbitraryLoads</key>
  <true/>
</dict>

You can also check some workaround here too !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM