Open external link from web app packaged as native iOS app - ios

I have a link on my mobile app (created with Sencha Touch 2) with a target="_blank" attribute. The app is packaged as a native iOS app. The problem is, the link is not opening in Safari as expected, instead it opens inside the app. It is very important that the link opens in Safari in a new browser window. How can I achieve that?
I should add that I am using the native packager of Sencha (sencha package). The default behaviour seems to open the new window in the same webview. But I need them to be opened in mobile Safari.
In an Xcode project I could do the following:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
[[UIApplication sharedApplication] openURL:request.URL];
return NO;
}
return YES;
}
How to do that with Sencha Touch native packaging?

I use this to open links in either Mobile Safari, or a new window. Works with Native iOS packaging and web apps:
function externalLink(link) {
try{
Ext.device.Device.openURL(link);
}catch(err) {
window.open(link, '_blank');
}
}

I haven't discovered a way to do this with sencha native packaging.
But wrapping the application in a phonegap and compiling the application in Xcode, with required urls added to the ExternalHost array in phonegap.plist should work right?
Also, (still on the Phonegap solution) I assume hacking AppDelegate.m to open links in Safari would work just as fine.

Programmatically (Javascript) opens a link in Mobile Safari.
Ideal if you cannot use a standard html link but you must use Javascript:
var a = document.createElement("a");
a.setAttribute('href', facebook);
a.setAttribute('target', '_blank');
a.click();

Related

How can a Developer Hand Over a Web Request to a Native iOS Application without displaying an error if the application is not installed?

So, we've all pretty much seen it. I tap a google plus link in Safari and it opens in the native Google Plus app. If the app is not installed, it takes me to the store to download it. It's a seamless transition.
As a developer, I would like this type of integration with my web application and native application. I've seen a way to call the native app using a custom url scheme, but this throws a nasty alert if the app isn't on the device.
I thought that the way around it might be creating a Safari extension, but that's not do-able with mobile safari.
How can I achieve this seamless transition effect?
This answer might help you to determine whether the app was installed or not from web app.
iPhone browser: Checking if iPhone app is installed from browser
If it's not installed you can continue redirecting to your web app instead of myapp://
The code from one of our web apps
var iOS = /(iPad|iPhone|iPod)/g.test( navigator.userAgent );
var messageContainer=$("#message");
if(!iOS)
{
messageContainer.html("Please open the link in your Apple mobile device")
}
else
{
setTimeout(function () {
messageContainer.html("Please install the app");}, 25);
window.location.href = "myapp://someInfo";
}

google maps opening in both native and web apps in ios using phonegap

I want to open the native application for direction in ios if it is installed in the iphone/ipad otherwise web app, but when i am using my code it is opening both native first and then web app if installed. My code is like:
setTimeout(function(){
window.open('http://maps.google.com/maps? saddr='+clat+','+clong+'&daddr='+lat+','+lng+'&directionsmode=driving','_blank');
},2000);
window.location='comgooglemaps://?saddr='+window.localStorage.getItem("clat")+','+window.localStorage.getItem("clong")+'&daddr='+lat+','+lng+'&directionsmode=driving';
How to solve this problem?
You can use inAppBrowser. It will automatically open the native google map in the device.
var ref = window.open(encodeURI('your google map url'), '_system', 'location=no');

How to open any iOS App from my own App

What I want to do is open any iOS Application (Evernote, safari, Facebook, etc) from my own iOS application. For example, I have created my app with two simple buttons, the first one is named "Evernote" and the second one is named "Safari", so when I click on the "Evernote" button I want that the Evernote App launch on my iOS device, the same when I click on the "Safari" button I want that the button opens my Safari App. How can I do that? It is that possible? If it is, please tell me how. Thank you very much.
yes it possible if you known this app scheme reference URL.
Example call Tel app:
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"tel://"]]){
NSString *tell = [#"tel://" stringByAppendingString:phoneNumber];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:tell]];
}
Safari and other is same way.
List common schemes Url here : http://wiki.akosma.com/IPhone_URL_Schemes
Hope this link helps you.
http://code.tutsplus.com/tutorials/ios-sdk-working-with-url-schemes--mobile-6629
If you need to open external apps from your app then follow the above link. Or if you need to open the iOS native apps like phone, mail, safari, etc, you can use URL schemes for opening the app.

IOS Web App open links within web app

I am in the mist of creating a mobile web app and have both meta tags
I have an iphone 5 on 7.0.4
When I click on a regular link like the one below it, opens up a mobile safari window and leaves the webapp. I also tried setting the target to _self and same behavior.
Sign in
I then used my ipad which was on 7.0.3 and it worked as should, not opening mobile safari on links. I think proceeded to update my ipad to 7.0.4 and the same issue as I had on my ipad.
Anyone ran into this issue and or knows a fix ?
Thanks
Since iOS 7.0.4 all links in WebApps open in Safari. As a workaround you can use Javascript:
window.location.href='text.html'
But remember that these steps will not be captured in history (so there is no ability to use Javascript like history.back() ..).
Alternatively, if you are using a menu in your web app, try to combine iframe and Javascript, you can change the content of your iframe with this Javascipt:
document.getElementById("frame").src = new_content.html
This will prevent your WebApp to open up links in Safari and stay in WebApp view.

How to open mobile webapp link in Safari from native Facebook app on iOS?

Our webapp works nicely inside the Facebook native iOS app. However, we have some links that need to open a new window in mobile Safari rather than opening inside the Facebook (UIWebView?) app. Just a plain HTML <a href="http://site...." target="_blank"> doesn't do it--still opens within the Facebook app (latest version.) Any way to get a plain link or a window.open() to switch to Safari for the page load ?
The web team on my company tried that approach and failed. What we ended up doing was using Facebook deep linking to handle this on our native iOS app.
You can find out more about Facebook deep linking here:
https://developers.facebook.com/docs/ios/link-to-your-native-app-ios-sdk/
It's a great solution if you already have an iOS app.
I hope this helps.

Resources