2017-08-03 110 views
0

我是这种开发中的新手。我正在为Visual Studio 2017中的IOS开发一个Xamarin表单。我需要为应用程序在WebView中显示特定url的html内容。我做到了这一点,我使用不同的网址进行了测试,显示的内容很好,但是当在http url中使用IP时,它不会显示任何内容。像这样的东西(很明显,我代替真实IP与X的):WebView没有在Xamarin Forms for IOS中显示任何东西

http://XX.XX.XX.XX:9090/banking/initAppn1.start()

据我所知,为了安全起见,苹果限制在URL中使用的IP(最全的,如果应用程序将在部署存储)以及使用不安全的协议(如http)时,文档指出:“自从版本9开始,iOS将只允许您的应用程序与默认实现最佳实践安全性的服务器进行通信,必须在Info.plist中设置值才能与不安全的服务器“。要启用一个特定的域绕过ATS要求根据文档我这样做是为info.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>UIDeviceFamily</key> 
    <array> 
     <integer>1</integer> 
     <integer>2</integer> 
    </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> 
    <key>MinimumOSVersion</key> 
    <string>6.0</string> 
    <key>CFBundleDisplayName</key> 
    <string>TestMobile</string> 
    <key>CFBundleIdentifier</key> 
    <string>com.yourcompany.TestMobile</string> 
    <key>CFBundleVersion</key> 
    <string>1.0</string> 
    <key>CFBundleIconFiles</key> 
    <array> 
     <string>[email protected]</string> 
     <string>Icon-76.png</string> 
     <string>[email protected]</string> 
     <string>Default.png</string> 
     <string>[email protected]</string> 
     <string>[email protected]</string> 
     <string>Default-Portrait.png</string> 
     <string>[email protected]</string> 
     <string>Icon-Small-40.png</string> 
     <string>[email protected]</string> 
     <string>Icon-Small.png</string> 
     <string>[email protected]</string> 
    </array> 
    <key>UILaunchStoryboardName</key> 
    <string>LaunchScreen.storyboard</string> 
    <key>CFBundleShortVersionString</key> 
    <string></string> 
    <key>NSAppTransportSecurity</key> 
    <dict> 
     <key>NSExceptionDomains</key> 
     <dict> 
      <key>XXX.XX.XX.XX:9090</key> 
      <dict> 
       <key>NSIncludesSubdomains</key> 
       <true/> 
       <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key> 
       <true/> 
       <key>NSTemporaryExceptionMinimumTLSVersion</key> 
       <string>TLSv1.1</string> 
      </dict> 
     </dict> 
    </dict> 
</dict> 
</plist> 

我不显示anyhting!之后,我尝试删除域中的端口,只使用IP地址,而我也不工作。

之后,我试图让任意负载是这样的:

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

任何显示!

目前,由于基础设施的原因,IP地址的域名不是由客户端提供的,但IP仅用于测试。

有人告诉我,他开发了类似的应用程序使用IP在网址和应用程序工作。

顺便说一下,在浏览器中使用URL是完美的!

请您需要帮助!谢谢

+0

我看不出有任何问题时指定NSAppTransportSecurity。你正在使用什么设备?你是否尝试过使用不同的http URI?你能否提供你使用的URI,以便我们可以重现这个问题 –

回答

0

我找到解决方案。一方面,如果应用程序将在应用程序商店中发布,则不能使用IP,因为它会因IPv6兼容性而被拒绝,这是我的情况,否则它可能仅使用IP来进行内部分发。 https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html

所以,我使用的域名,没有港口和NSExceptionDomains:在二手,通过使用不安全的网址(HTTP),您必须使用NSExceptionDomains根据文档配置NSAppTransportSecurity与在URL中没有端口的info.plist这就是全部,它的工作。谢谢!

0

使用:

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

你会禁用ATS,它会拒绝你的申请,在应用程序审查过程中,没有为它的有效理由。

正如您所说的,正确的方法是使用NSExceptionDomains字典填充无法通过HTTPS协议访问的URL。 另一个禁用ATS的Web视图的方法是使用关键:

NSAllowsArbitraryLoadsInWebContent 

那如果启用,禁用来自网络的意见提出了要求所有ATS的限制。这可让您的应用使用可显示任意内容的嵌入式浏览器,而不会为其他网址禁用ATS。

Reference