Determining if a Facebook application is installed from Unity

We are using the SDK for Unity (v6.0), and now I want to see if there is a way to check if the Facebook application is installed on the device.

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

I want to identify this scenario (only happens when installing the FB application) and respond accordingly.

+4
source share
1 answer

"To use your own plugin, you first need to write C functions to access the functions you need and compile them into a library. In Unity, you will also need to create a C # script that calls the 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 connection between Unity and Native Code.

The code you need to implement to check Facebook APP;

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

However, you need some connection between the Unity project and Xcode. In this way,

 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 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 ();
   }
}
+1
source

Source: https://habr.com/ru/post/1570478/


All Articles