1

We have a game which is facebook connected- we have a facebook canvas and also a native mobile app for ios and for android that is defined in facebook dashboard and deep linking is enabled. We want to share a link in our fan page that will do this when clicked by the user:

  1. If the user didn't approve our app before he will be asked to approve our facebook app.
  2. If the user is using a desktop device he will be redirected to our canvas page. However if the user is using a mobile device and the app is installed on his device, he should be directed to the mobile app directly on his app (deep linking). If he using a mobile device and the app is not installed on his device, it should take the user to the relevant app store.

Any idea how we can deep link(using facebook?) to our mobile apps from our facebook fan page?

Thanks!

AJ222
  • 1,114
  • 2
  • 18
  • 40

1 Answers1

1

For iOS you could use url schemes to direct users to your app, to check whether the app is installed on a device or not, do this.

if([[UIApplication sharedApplication] canOpenURL:[NSURL urlwithString:@"YourAppsScheme"]])
{
   //your app is installed on the device, open your app using
  [[UIApplication sharedApplication] openURL:[NSURL urlwithString:@"YourAppsScheme"]]
}

else
{
  [[UIApplication sharedApplication] openURL:[NSURL urlwithString:@"your applications itunes url"]] //

}

For Android you do the same kind of thing but you check the pacakge name exists on a device or not, How to check programmatically if an application is installed or not in Android?

sample snippet for Android:

installed  =   isPackageInstalled(APPPACKAGE);
        if (installed) {
Intent i;
PackageManager manager = getPackageManager();
try {
    i = manager.getLaunchIntentForPackage(APPPACKAGE);
    if (i == null)
        throw new PackageManager.NameNotFoundException();
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    startActivity(i);
} catch (PackageManager.NameNotFoundException e) {

}      

}

else
{
// open google play app details page of your app

    final String appName = ...;
    try
    {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+appName)));
    } 

    catch (android.content.ActivityNotFoundException anfe) {
    startActivity(new Intent(Intent.ACTION_VIEW,    Uri.parse("http://play.google.com/store/apps/details?id="+appName)));

    }
}

private boolean isPackageInstalled(String packagename, Context context) {
    PackageManager pm = context.getPackageManager();
    try {
        pm.getPackageInfo(packagename, GET_ACTIVITIES);
        return true;
    } catch (NameNotFoundException e) {
        return false;
    }
}

Doing this from a web page,

<script type="text/javascript">
function startMyApp()
{
  document.location = 'yourAppScheme://';
  setTimeout( function()
  {
      if( confirm( 'You do not seem to have Your App installed, do you want to go download it now?'))
      {
        document.location = 'http://itunes.apple.com/us/app/yourAppId';
      }
  }, 300);
 }
</script>
Community
  • 1
  • 1
Satheesh
  • 10,998
  • 6
  • 50
  • 93