如何在我的mac os上从我的iphone连接到我的localhost

时间:2015-11-14 11:30:06

标签: ios objective-c iphone swift macos

我读了很多关于它的问题,但我仍然有问题。

当我使用localhost并从我的模拟器中更正 NSAppTransportSecurity optinos时,一切都是正确的。

现在我正在调试我的iphone。 iphone和mac都连接到同一个网络。

我检查我的mac的IP地址

我将它添加到 NSAppTransportSecurity ,如下所示:

  <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>10.250.x.x</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSTemporaryExceptionMinimumTLSVersion</key>
                <string>TLSv1.1</string>
            </dict>
        </dict>
    </dict>

我仍然收到错误:

 App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
error = Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." UserInfo={NSUnderlyingError=0x7f904d300170 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 "(null)"}, NSErrorFailingURLStringKey=http://10.250.x.x:8080/IVRServer/api/registration/register, NSErrorFailingURLKey=http://10.250.x.x:8080/IVRServer/api/registration/register, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.}

我应该为我的plist添加其他东西吗?

请不要认为这个问题是重复的,因为我已经在我的plist中使用了正确的设置,它工作正常,但就在我将服务器更改为localhost时它无法正常工作

我错过了什么?

1 个答案:

答案 0 :(得分:2)

如果您只想绕过此限制,请允许所有加载:

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

这应该是可行的,因为大概是你正在使用你的本地主机&#34;所以不应该有任何安全问题。