4

We are using the Facebook SDK for Unity (v6.0) and I'd like to now whether there's a way that I can check if the Facebook app is installed on the device.

The reason is an existing bug in the Facebook SDK (see here: bug)

I want to identify this scenario (occurs only when the FB app is installed), and react accordingly.

lysergic-acid
  • 19,570
  • 21
  • 109
  • 218
  • 1
    Pretty sure you'll need to use native code for this, so if you don't get any answers here, you might try asking a more general question (or looking for an existing one) such as "iOS, detect if another app is installed?" or "iOS, detect if Facebook is installed?".. then just research how to write a native plug-in for Unity, if you don't already know how. – eselk Jan 08 '15 at 16:02
  • Does this help? http://forum.unity3d.com/threads/check-if-other-app-is-installed-on-device.272548/ Check the answer by Graham. I don't use iOS, so I don't know if this really answer the quetion, though. – Andrea Jan 08 '15 at 16:21
  • You can check it using a native plugin, but it will be platform specific. I can help you with android, but no idea how to implement that for iOS. – Juanjo Vega Feb 13 '15 at 16:41
  • I have upped the question. Because no one really tries to check if is going to work or not. There is no actual testing that you can do in the Unity3D engine as it is not installed in the Android and the Unity3D Remote is just a streaming mirror that you get in the android. So this is an interesting question indeed. – Aizen Mar 29 '15 at 04:50
  • possible duplicate of [How to detect if Facebook app is installed on iOS?](http://stackoverflow.com/questions/19690170/how-to-detect-if-facebook-app-is-installed-on-ios) – Almo Apr 20 '15 at 20:30

1 Answers1

1

"In order to use a native plugin you firstly need to write functions in a C-based language to access whatever features you need and compile them into a library. In Unity, you will also need to create a C# script which calls functions in the native library." from http://docs.unity3d.com/Manual/NativePlugins.html

So, basically you need to write your code in Objective-C and provide the communication between the Unity and the Native Code.

The code that you need to implement for checking Facebook APP is;

(void) checkFacebookApp
{
   if ([[UIApplication sharedApplication] canOpenURL:[NSURLURLWithString:@"fb://"]])   
   {
      return true;
   }
}

However you need some communication between the Unity and Xcode project. So;

 class SomeScript : MonoBehaviour {

   #if UNITY_IPHONE || UNITY_XBOX360

   // On iOS and Xbox 360 plugins are statically linked into
   // the executable, so we have to use __Internal as the
   // library name.
   [DllImport ("__Internal")]

   #else

   // Other platforms load plugins dynamically, so pass the name
   // of the plugin's dynamic library.
   [DllImport ("PluginName")]

   #endif

   private static extern float checkFacebookApp ();

   void Awake () {
      // Calls the FooPluginFunction inside the plugin
      // And prints 5 to the console
      bool check = checkFacebookApp ();
   }
}
jazz
  • 232
  • 1
  • 2
  • 10