lysergic-acid lysergic-acid - 8 months ago 67
iOS Question

Determining if Facebook app is installed from Unity

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.

Answer Source

"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

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 {


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


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


   private static extern float checkFacebookApp ();

   void Awake () {
      // Calls the FooPluginFunction inside the plugin
      // And prints 5 to the console
      bool check = checkFacebookApp ();