如何使用cocoaHTTPServer在IOS上创建HTTPS服务器?

时间:2017-03-14 03:05:05

标签: ios objective-c ssl https cocoahttpserver

我制作了一个javascript云应用程序,它运行在我的iPad应用程序上的webview中的网页上,通过WebSocket连接进行通信,但它只能在我的http网站上使用而不是https,否则我得到 CFNetwork SSLHandshake失败(-9806)错误在Xcode和网站上说它在握手期间超时。

这是因为iPad上的网络服务器是在HTTP而不是HTTPS上运行的?

JAVASCRIPT CLOUD APP

当连接到iPad上的Web服务器时,云中的这部分适用于HTTP。

var protocol = "ws";
if (this.useSecureConnection)
    protocol = "wss";
var url = protocol+'://localhost:'+this.port+'/service';
this.connection = new WebSocket(url);

Xcode iOS iPad App(Objective-C)

我认为这是问题所以我尝试启用HTTPS,但我不确定要为" sslIdentityAndCertificates"创建什么?方法

- (BOOL)isSecureServer
{
     HTTPLogTrace();

     // Override me to create an https server...

     return YES;
}

/**
 * This method is expected to returns an array appropriate for use in kCFStreamSSLCertificates SSL Settings.
 * It should be an array of SecCertificateRefs except for the first element in the array, which is a SecIdentityRef.
**/
- (NSArray *)sslIdentityAndCertificates
{
    HTTPLogTrace();
    return nil;
}

我见过的其他一些帖子使用的API只适用于Mac而不是iOS。

我也尝试了几种ATS权限组合。所有这些都导致HTTPS不允许WebSocket连接。

非常感谢任何帮助! :)

0 个答案:

没有答案