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.