2016-12-31 183 views
-1

我試圖訪問本地ip地址,以便我可以更改/更新本地覆盆子pi上的信息。即IM使用下列內容:使用xcode訪問本地ip地址

https://github.com/Jopyth/MMM-Remote-Control 

香港專業教育學院更新了我的plist看起來像這樣:

<?xml version="1.0" encoding="UTF-8"?> 
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
    <plist version="1.0"> 
    <dict> 
     <key>CFBundleDevelopmentRegion</key> 
     <string>en</string> 
     <key>CFBundleExecutable</key> 
     <string>$(EXECUTABLE_NAME)</string> 
     <key>CFBundleIdentifier</key> 
     <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> 
     <key>CFBundleInfoDictionaryVersion</key> 
     <string>6.0</string> 
     <key>CFBundleName</key> 
     <string>$(PRODUCT_NAME)</string> 
     <key>CFBundlePackageType</key> 
     <string>APPL</string> 
     <key>CFBundleShortVersionString</key> 
     <string>1.0</string> 
     <key>CFBundleVersion</key> 
     <string>1</string> 
     <key>LSApplicationCategoryType</key> 
     <string></string> 
     <key>LSRequiresIPhoneOS</key> 
     <true/> 
     <key>NSAppTransportSecurity</key> 
     <dict> 
      <key>NSExceptionDomains</key> 
      <dict> 
       <key>http://192.168.0.40</key> // need to add your domain name of webservice 
       <dict> 
        <key>NSIncludesSubdomains</key> 
        <true/> 
        <key>NSExceptionAllowsInsecureHTTPLoads</key> 
        <true/> 
        <key>NSExceptionRequiresForwardSecrecy</key> 
        <true/> 
        <key>NSExceptionMinimumTLSVersion</key> 
        <string>TLSv1.2</string> 
        <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key> 
        <false/> 
        <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> 
        <true/> 
        <key>NSThirdPartyExceptionMinimumTLSVersion</key> 
        <string>TLSv1.2</string> 
        <key>NSRequiresCertificateTransparency</key> 
        <false/> 
       </dict> 
      </dict> 
     </dict> 
     <key>NSTemporaryExceptionMinimumTLSVersion</key> 
     <string>TLSv1.1</string> 
     <key>UILaunchStoryboardName</key> 
     <string>LaunchScreen</string> 
     <key>UIMainStoryboardFile</key> 
     <string>Main</string> 
     <key>UIRequiredDeviceCapabilities</key> 
     <array> 
      <string>armv7</string> 
     </array> 
     <key>UISupportedInterfaceOrientations</key> 
     <array> 
      <string>UIInterfaceOrientationPortrait</string> 
      <string>UIInterfaceOrientationLandscapeLeft</string> 
      <string>UIInterfaceOrientationLandscapeRight</string> 
     </array> 
     <key>UISupportedInterfaceOrientations~ipad</key> 
     <array> 
      <string>UIInterfaceOrientationPortrait</string> 
      <string>UIInterfaceOrientationPortraitUpsideDown</string> 
      <string>UIInterfaceOrientationLandscapeLeft</string> 
      <string>UIInterfaceOrientationLandscapeRight</string> 
     </array> 
    </dict> 
    </plist> 

但SIM或設備裝載時,我仍然得到一個空白,儘管黑暗的一頁。

我做了最基本的應用程序,以便我的兄弟可以訪問他的魔鏡時,他在家裏更新,但我似乎無法看到本地IP地址。任何幫助都會很棒。

+0

你打算把這個提交給蘋果公司,或只是把它給你的兄弟和更新配置文件每年的應用程序? – wottle

+0

例外域不適用於IP地址。 – wottle

回答

1

實際上,真正的問題是ATS異常不適用於IP地址。它僅適用於域名

選項:

選項1 - 禁用ATS

關閉ATS一共是不是一個好主意,如果你正在提交您的應用程序到應用程序商店 - 這樣會使你來證明當蘋果開始執行該規則時,如果您希望將其提交給應用商店,那麼可以做出決定。通常我不建議將此作爲SO的一個選項。但是,考慮到您在那裏放置了一個硬編碼的IP地址,我懷疑這是針對特定用例創建的一次性應用程序,並且您不需要提交給Apple進行審閱(您可能會直接在設備上進行安裝使用開發配置文件)。如果是這樣的話,我會完全使用Info.plist中的NSAllowsArbitraryLoads鍵來禁用ATS。

enter image description here

這將禁用所有ATS的保護,但如果您的應用程序僅在本地網絡實體通過HTTPS通信,應用程序傳輸安全性就不會被保護反正什麼。

選項2 - 使用NSAllowsLocalNetworking

如果你把兩個NSAllowsArbitraryLoadsNSAllowsLocalNetworking在Info.plist中,iOS中9,將禁用ATS完全,但在iOS的10(即支持NSAllowsLocalNetworking的第一個版本設置),iOS將忽略NSAllowsArbitraryLoads,並且僅在本地網絡呼叫上禁用ATS。這樣會更安全,但是如果您只是進行本地網絡呼叫,那麼我只會禁用ATS(選項1)。

選擇3 - xip.io

如果你想離開ATS上,其他人使用xip.io服務「轉換」本地IP地址到域名取得了成功。因此,您需要將xip.io添加到Exception域,並將NSIncludesSubdomains的子值設置爲true。然後,當你連接到你的域名,而不是連接到192.168.0.40,你會連接到192.168.0.40.xip.io