【问题标题】:how to connect from my iphone to my localhost on my mac os如何从我的 iphone 连接到我的 mac os 上的本地主机
【发布时间】:2016-02-15 22:20:15
【问题描述】:

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

当我使用 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 时它不起作用

我错过了什么?

【问题讨论】:

    标签: ios objective-c iphone swift macos


    【解决方案1】:

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

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

    这应该是可行的,因为大概您使用的是“本地主机”,因此不应该有任何安全问题。

    【讨论】:

    • 现在我没有收到那个错误,但是我收到错误 404 not found,为什么?
    • @JackSong 没关系,我可以“负担得起”。不过,感谢您的留言,您真的很周到。
    猜你喜欢
    • 2014-04-30
    • 2013-11-29
    • 2014-02-24
    • 2019-08-29
    • 1970-01-01
    • 1970-01-01
    • 2020-07-16
    • 2019-06-16
    • 1970-01-01
    相关资源
    最近更新 更多