Facebook profile link from safari to facebook app - ios

I am making a personal website with a link to a Facebook profile. If you go to the website from iOS device, I would like the link to open in application, not safari, because a lot of people are not logged-in in safari.
Now this can be done by using "fb://profile/" instead of the link facebook.com/. And I have used following simple code to switch the links:
$(function(){
var iOS = ( navigator.userAgent.match(/(iPhone)/g) ? true : false );
if (iOS){
var href= $(".fb-link").attr("href");
var res = href.split("/");
var username = res[res.length - 1];
$(".fb-link").attr("href", "fb://profile/" + username);
}
});
The only problem is when user does not have the app, then it not only won't open in an app but will fail to open completely.
Is there a way to test if the app is installed? I know when I am programming in the iOS native app I can test if fb:// responds and then I can use the link, but the safari is way more limited. I know it probably won't be possible, just trying if anybody has some experience with this.
Also - is there something similar for android? I don't have much experience with that.
Thanks

There's no way in Safari (from a webpage) to determine whether an app is installed or not. The only thing you can try to do is do the fb://profile redirect in javascript, and then set a timeout on your page to see if the redirect succeeded or not. But this is not optimal as there can be error dialogs that pop up.
For Android, you should just go to the www url, and let the Android app handle it via its own intent filter.

Related

Launching an App from Custom URL from Safari not working as intended in iOS >12.3

We share the App deeplinks (Universal links) with our users over email, sometimes they get wrapped by email service providers for safety.
When user taps on these wrapped deeplinks, instead of opening the App directly it opens the url in Safari.
We have a page hosted on that url. We capture the deeplink there and try to open the App using Custom URL scheme (myurlscheme://). But if the App is not installed, we try to redirect the user to the App Store page.
It all worked okay until now, but seems like Apple made some changes in Safari in the new versions of iOS (>12.3).
What’s happening now is, if the App is installed and we open the App from Safari (from Custom URL), the App Store page opens in a split second after opening our App.
This is the Javascript code that we are using:
window.location.href = 'myurlscheme://';
setTimeout(function() {
window.location.href = "https://itunes.apple.com/us/app/myapp/id123456789?ls=1&mt=8";
}, 500);
Is anyone else experiencing this. If yes, were you able to find any solution?
Update:
If we set the timeout to 4000 (i.e. 4 seconds), then it does not redirect to the App Store after launching the App.

Opening apps with custom protocols (twitter://, instagram://) in Cordova/PhoneGap on iOS

I can't seem to use custom URL protocols to open the apps that are installed on an iPhone; even with InAppBrowser installed.
For example:
// Instagram
window.open('instagram://user?username=jgillick', '_system', 'location=no');
// Twitter
window.open('twitter://user?screen_name=jgillick', '_system', 'location=no');
Both of these things do absolutely nothing. They don't even open the InAppBrower window.
Facebook is a really interesting one. Instead of using a custom protocol, if you try to access https://www.facebook.com/<facebook ID number> on your phone, the Facebook app will automatically take over (you can use this tool to find your facebook ID). This works when I put it in Safari on my iPhone, but doesn't in the InAppBrowser, it just opens the app browser and directs me to the logged-out version of that page.
// Facebook
window.open('https://www.facebook.com/763639132', '_system', 'location=no');
I'm at a complete loss for getting this working.
For some reason the window.open('...', '_system') method suddenly just started working. I'm not sure why it wasn't before.
For me that wasn't giving anything useful
window.open('...', '_system')
what worked was:
window.location = 'instagram://media?id=' + id;
window.location = 'fb://post/' + id;
of course those native apps have to be installed, otherwise no action will happen.
this might come handy https://github.com/ohh2ahh/AppAvailability

How does LinkedIn suppress mobile safari "invalid address" warnings, for deeplinks to their iOS app when it's not installed?

How can mobile safari "invalid address" warnings be suppressed, for links to an iOS app that's not installed?
I don't want to use a Smart App Banner (too little control over UX).
I don't want to pay nor integrate with a 3rd party vendor ($, dependency).
The use case is simple to understand:
In mobile Safari (eg on an iPhone): follow a link to my mobile-web-friendly page (eg "www.example.com/mw-foo.html"). If my native iOS app is installed, route / redirect the user to an app deeplink within it (e.g. "com.example.app://my-deeplink"). (Note the mapping from mw url to the app uri is easily managed in an apache rewritemap or a js collection object, that's the easy part.) The real challenge is:
If the app is NOT installed, suppress the "invalid address" popup warning gracefully (allowing me to decide whether it's a NOOP / stay on the mw page, or to route the user to the app store to install the app).
How is it possible to work around this bad UX? I've seen half-baked solutions involving iframe injection and race conditions with "magic numbers" for timeouts, pagehide event listeners and window.location overrides... but none of them seem able to reliably work around the popup. A solution that seemed close was this one:
http://www.mazdigital.com/blog/post/2014/deep-links-on-mobile-browsers-demystified
... but it doesn't prevent the warning from appearing either.
I'd considered declaring it impossible, except that a few big enterprises seem to have managed it (e.g. LinkedIn). But I haven't succeeded in reverse-engineering their approach from the outside.
A good solution here would be a huge benefit to the community (and to me personally). If anyone can describe exactly how LinkedIn manages this, I'd be extremely grateful. Also, thanks in advance for helpful feedback / links to gists or posts, ideally which you've actually used and can vouch for. Thank you!
PS Not really a DUP of this one:
how to prevent iOS safari alert when trying to open non-installed native app?
because they don't answer how LinkedIn does it (and the suggested answers there don't work).
They are using the smart banner API.
From their minimized code on their touch webpage (formatted):
var smartBannerIOS = {};
(function(c) {
c.initialize = function() {
var a = c.createMetaTagContent();
metaBanner = document.createElement("meta");
metaBanner.setAttribute("name", "apple-itunes-app");
metaBanner.setAttribute("content", a);
document.getElementsByTagName("head")[0].appendChild(metaBanner)
};
c.createMetaTagContent = function() {
var a = window.location.hash;
a || (a = "#home");
var b = "";
b = a.indexOf("?") >= 0 ? "&smartbanner=1" : "?smartbanner=1";
var d = $initMetrics && $initMetrics.getServerData();
if (d && d.isLoggedIn)
b += "&logged_in=1";
b += "&session_id=" +
($initMetrics && $initMetrics.sessionId);
return "app-id=288429040, app-argument=" + ("linkedin://" + a + b)
}
})(smartBannerIOS);
smartBannerIOS.initialize();
It's documentation can be found here: Apple Dev Docs - Promoting Apps with Smart App Banners
Open the native app in the iframe will suppress mobile safari "invalid address" warnings. This code works for me:
https://gist.github.com/zengfenfei/51b36c008faaea4cb934

How to launch AppWorld from an application? [BlackBerry]

This might be a easy question but i couldn't find solution. I want to open AppWorld by clicking a button in my BB application. For example when user clicks this button Appworld will show "Facebook Application" page. Can i do this?
In Android platform this line launches GooglePlay for Facebook App. Does BlackBerry supports this kind of method?
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.facebook.katana")));
Here is a simple way to do this:
Browser.getDefaultSession().displayPage("http://appworld.blackberry.com/webstore/content/2360/?lang=en");
Above code will invoke the browser in the application and open the BlackBerry App World, I tested it in device and it's perfectly working. For now I put a Whats App messenger link, but you can customize the link according to your requirement.
You can open App World from your BB application directly using the following code. This code avoids opening the browser first.
Registry registry = Registry.getRegistry(this.getClass().getName());
Invocation invocation = new Invocation(null, null,
"net.rim.bb.appworld.Content",
false, ContentHandler.ACTION_OPEN);
invocation.setArgs(new String[] { /* app id in appworld */ });
registry.invoke(invocation);

Test if any app can handle a url scheme in mobile safari on iOS

Is there any way to test if an iOS can handle a custom URL scheme? I have an app that registered a custom url scheme to be able to open the app from a hyperlink in mobile safari. How ever, I'd like to tell the user they need to go to the appstore to download the app if they dont have it installed.
Is there a clever way to test a URL and catch when it fails and the reason for it to fail?
This is the best I can come up with, but it's only tested in iOS 5:
If your link in mobile safari is link text,
change it to: link text,
then at the top of the /launchapp page, put a hidden iframe with the desired URL: <iframe src="myapp://path" style="display:none"></iframe>. In the body of the page, put your message about needing to go to the appstore to download the app.
If the user has the app:
They will not see the launchapp page, they will be directed seemlessly to the app url.
If the user does not have the app:
They will get a nasty alert about 'The URL could not be loaded', click OK, then they will be looking at your 'you need to download the app' page.
Update - March 2013
Check out this comment on a related SO answer. Apparently, if your app isn't already installed, you can seamlessly redirect to your app in the App Store using an approach like this (not tested):
// setup fallback (redirect to App Store)
var start = (new Date()).valueOf();
setTimeout(function() {
var end = (new Date()).valueOf();
// prevent App Store redirect upon returning to safari from myapp
if (end - start > 1000) return;
// get a seamless redirect if you use itms://... instead of http://itunes.com/...
window.location = 'itms://my/app/URI';
}, 25);
// Attempt to load my custom url scheme
window.location = 'myapp://my/path'

Resources