CanOpenUrl method not working ios 9

天涯浪子 提交于 2021-01-28 20:02:12

问题


I have used CanOpenUrl method in my app, and it was working on iOS 8.4 but when I changed to simulator to 9.2, it's not working. I couldn't find the reason. These are my codes;

if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"deeplinking://"]]){
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"deeplinking://"]];
}
else{
     NSLog(@"not working!");
}

Can anybody help me? Thank you, Halil.


回答1:


for security purpose Apple has introduced the new concept of NSAppTransportSecurity in iOS 9 and above ,it is needed

You have to add just the NSAllowsArbitraryLoads key to YES in NSAppTransportSecurity dictionary in your info.plist file.

For example,

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

you can see this document in apple. for example




回答2:


Add below things in your .plist

App Transport Security Settings Dictionary

Allow Arbitrary Loads Boolean YES




回答3:


Please implement Application Transfer Protocol

add

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

in plist




回答4:


The above answer is correct but it is not recommended to allow all arbitary loads, as it allows all non secure connection to be carried out. Instead you can allow only some specific web urls to work without ssl certificate and is the recommended way.

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>yourserver.com</key>
    <dict>
      <!--Include to allow subdomains-->
      <key>NSIncludesSubdomains</key>
      <true/>
      <!--Include to allow HTTP requests-->
      <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
      <true/>
      <!--Include to specify minimum TLS version-->
      <key>NSTemporaryExceptionMinimumTLSVersion</key>
      <string>TLSv1.1</string>
    </dict>
  </dict>
</dict>


来源:https://stackoverflow.com/questions/35746179/canopenurl-method-not-working-ios-9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!