Reputation: 2299
I have to clarify that I know how to open url from our iOS app, like
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: urlAddress]];
In my code I have done the same. It is an old app and I have to upgrade this app right now. I'm working on Xcode 7 right now. It has a code to open my website from the app. For that I have coded below for my website. I have also tried fro all other main site url but it still not opening safari to open this page.
NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
if([[UIApplication sharedApplication] canOpenURL:url]) {
NSLog(@"OK");
[[UIApplication sharedApplication] openURL:url];
} else {
NSLog(@"Failed to open url: http://www.google.com");
}
I have printed it that it goes in condition canOpenURL:url
and it prints OK
but it will not redirect to safari. I have checked in simulator and also in device but the result is same. Please help. Thanks in advance.
==== EDIT =======
This may be helpful more information about app.
It is tabbarcontroller app and navigation bar is shown for all views.
The above code is in button action
-(IBAction)onSiteClick:(id)sender
{
NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
if([[UIApplication sharedApplication] canOpenURL:url]) {
NSLog(@"OK");
[[UIApplication sharedApplication] openURL:url];
} else {
NSLog(@"Failed to open url: http://www.google.com");
}
}
If I put this code in app delegate didFinishLaunchingWithOptions
method then it open safari and works. But it is not working on button click. Even I have tried code in viewDidLoad
and viewWillAppear
, then also it is not working.
===== EDIT 1 ====
I have not found solution for this yet. So for now I have taken a web view inside app and open the link in app.
Upvotes: 1
Views: 4531
Reputation: 2999
the code is working fine in Xcode 7, iOS 9.0 ,os x 10.11
So, I think no issue with security.
Upvotes: 0
Reputation: 3811
Hope this helps you:
<key>NSAppTransportSecurity</key>
<dict>
<!--Include to allow all connections -->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Upvotes: 0
Reputation: 13020
This is a new security feature of iOS 9. you need to add url in plist.
<key>LSApplicationQueriesSchemes</key>
<array>
<string>http://www.google.com</string>
</array>
Upvotes: 1