简体   繁体   English

在ios上,在离子混合应用程序中,如何绕过证书检查(使用自签名证书)

[英]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 我的离子/ cordova应用程序现在在与HTTPS后端一起使用时会出错

`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. 我在我的开发环境中,使用自签名证书,并使用IP地址连接后端。

I examined the certificate using openssl s_client and it looks valid. 我使用openssl s_client检查了证书,看起来有效。 As a matter of fact I am able to use the same backend with android version of this hybrid app. 事实上,我可以使用与这个混合应用程序的Android版本相同的后端。

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? 是否有一些plist或其他Xcode设置接受自签名证书或一起忽略此测试 - 类似于NSAppTransportSecurity::NSAllowsArbitraryLoads设置?

--EDIT - 编辑

I have <access origin="*"/> in my config.xml file. 我在config.xml文件中有<access origin="*"/>

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 您可以在AppDelegate.m的末尾添加它,但仅出于测试目的,您应该在发布应用程序之前将其删除,如果应用程序包含该代码,Apple可能不会批准该应用程序

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

Try adding this to info.plist 尝试将此添加到info.plist

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

You can also check some workaround here too ! 您也可以在这里查看一些解决方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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