问题
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