iOS9: Cannot open http link with Safari from 'openurl' method - objective-c

I cannot open the http link with Safari using 'openurl' method, if Safari is not opening in the background. But if Safari is running in background process, the app can open the http link with Safari successfully. I am not sure whether this is one of iOS9 changes.
Here is my code
BOOL isAppInstalled = [[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:[DELEGATE advertiseUrl]]];
if(isAppInstalled) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://stackoverflow.com"]];
}

Related

WKWebView Open _Bank Target Links in Safari

I am very new so bear with me. I had an youtube video embed in a WKWebView playing fine on macOS in Objective-C. At first, none of the standard youtube links on the video (channel, recommended videos, etc) would load. I think this was because youtube uses _blank target links. The following code fixed it so any video links will now open in the WKWebView.
- (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures
{
NSLog(#"createWebViewWithConfiguration %# %#", navigationAction, windowFeatures);
if (!navigationAction.targetFrame.isMainFrame) {
[(WKWebView *)_webView loadRequest:navigationAction.request];
}
return nil;
}
However, I would like these links to open in the macOS browser, and not WKWebview. Lot's of swift examples on iOS, but can't seem to get links to open from WKWebView in safari.
I have tried:
if (!navigationAction.targetFrame.isMainFrame) {
[[NSApplication sharedApplication] openURL:[navigationAction.request URL]];
}
But doesn't work on macOS
This is what eventually worked for me. Seems to open any url (including javascript type popovers used in YouTube) in Safari instead of opening them in WKWebView (or not opening them at all).
- (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures
{
NSLog(#"createWebViewWithConfiguration %# %#", navigationAction, windowFeatures);
if (!navigationAction.targetFrame.isMainFrame) {
[[NSWorkspace sharedWorkspace] openURL:[navigationAction.request URL]];
}
return nil;
}
Not 100% sure but I've seen this circulated online for opening URLs on Mac. Give it a try.
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:#"http://stackoverflow.com"]];

How to redirect a URL to open in puffin browser instead of safari browser in ios app?

As like we use this to open URL in facebook app. I want to open URL in puffin browser.
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"fb://"]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"fb://profile/355356557838717"]];
}
else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"https://www.facebook.com/DanielStormApps"]];
}
let urlPath: String = "puffin://www.facebook.com"
let url: NSURL = NSURL(string: urlPath)!
let isInstalled = UIApplication.sharedApplication().canOpenURL(url)
if isInstalled {
print("Installed")
}else{
print(" Not Installed")
}
You can use 'puffin://' to open URL in http. Or use 'puffins://' to open URL in https.
Add infoplist file
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fb</string>
</array>
You are open that type url :[NSURL URLWithString:#"fb://profile/355356557838717"]

why UIApplicationOpenSettingsURLString is crashing on camera switch change?

NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:url];
its work fine for other settings like :
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=General&path=Keyboard"]];
or wifi or general
Its crashing with Message from debugger: Terminated due to signal 9 for only UIApplicationOpenSettingsURLString when switch state change ON/OFF
else if we don't change switch state change ON/OFF then it debug properly, visit all the delegate methods.

Open the Bluetooth Settings Menu in Ios 10

I need to open the bluetooth settings menu in IOS10 and above.But [[UIApplication sharedApplication] openURL:
[NSURL URLWithString:#"prefs:root=Bluetooth"]]; is not working in ios 10.
After exploring multiple document I got below link which provide code which will work properly. https://gist.github.com/johnny77221/bcaa5384a242b64bfd0b8a715f48e69f
But, Now I have question will app store accept this patch code or they will reject application.
Please help me to solve this issue.
Thanks in advance
Swift 3.0:- Working in all iOS version upto iOS 10.2
let url = URL(string: "App-Prefs:root") //for system setting app
#IBAction func blutootheButtonTapped(_ sender: AnyObject) {
let url = URL(string: "App-Prefs:root=Bluetooth") //for bluetooth setting
let app = UIApplication.shared
app.openURL(url!)
}
As of iOS 10 "App-Prefs:root" should be used rather than "prefs:root". See below Objective C code. Tested this , code works fine but Apple may reject the app because of this.
NSString *settingsUrl= #"App-Prefs:root=Bluetooth";
if ([[UIApplication sharedApplication] respondsToSelector:#selector(openURL:options:completionHandler:)]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:settingsUrl] options:#{} completionHandler:^(BOOL success) {
NSLog(#"URL opened");
}];
}

iPhone sdk - open app store to specific app?

Is there a way to open the app store to a specific application?
I tried using something like the following:
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:#"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=284417350&mt=8&uo=6"]];
But got the following: "Safari cannot open the page because to many redirects occurred".
Apparently this issue only affects the simulator. A build an go on the device works perfect.
Use http://itunes.com/app/YourAppNameWithoutSpaces
See also this.
Another simple way is:
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:#"itms-apps://itunes.com/app/YourAppNameWithoutSpaces"]];
This is very clean
You can open app without opening safari
NSString *appId = #"you appid"; //like 999999999
NSString *link = [#"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=" stringByAppendingString:appId];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:link]];
Replace iTunesLink with your App URL.
NSString *iTunesLink = #"https://itunes.apple.com/us/app/digital-speedometer-pro/id1021728349?mt=8";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
Starting from iOS 6 right way to go is using SKStoreProductViewController class.
Code is here: https://stackoverflow.com/a/32008404/1151916