2017年3月8日 星期三

how to accept Http url in iOS app

Since iOS 9, http url will be rejected in iOS App as default. Of course, it relates security issues

What is App Transport Security (ATS)?

In order to support http url in iOS, it must modify plist files in iOS project.

If you utilize react-native CLI to create project, you can find a folder 'ios' under created project

where 'reactNavSample' is project name. If you want to active http url, open Info.plist and find NSAppTransportSecurity key then add 

  <key>NSAllowsArbitraryLoads</key>   
  <true>   

* adding NSAppTransportSecurity represents that all domains are allowed to access

If you don't want to allow all domains access, you can also specify specific domain. For example, you can enable http://localhost by adding

   <key>localhost</key>   
   <dict>    
      <key>NSExceptionAllowsInsecureHTTPLoads</key>   
   </dict>   



* If you specify specific domain, it might be a problem if the domain links resources from the others. For example, if you allow abc.com domain, it will be find when you access http://abc.com. However, if abc.com links resources come from def.com, it might be a problem. The key issue is, you will never know whether abc.com links resources come from others, def.com? ghi.com? or jkl.com?


沒有留言:

張貼留言