确定 Facebook 应用程序是否从 Unity 安装
Determining if Facebook app is installed from Unity
我们正在使用 Facebook SDK for Unity (v6.0),现在我想知道是否有一种方法可以检查设备上是否安装了 Facebook 应用程序。
原因是 Facebook SDK 中存在错误(参见此处:bug)
我想识别这种情况(仅在安装 FB 应用程序时发生),并做出相应的反应。
"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
所以,基本上你需要在 Objective-C 中编写你的代码,并提供 Unity 和本机代码之间的通信。
检查Facebook APP需要实现的代码是;
(void) checkFacebookApp
{
if ([[UIApplication sharedApplication] canOpenURL:[NSURLURLWithString:@"fb://"]])
{
return true;
}
}
但是您需要在 Unity 和 Xcode 项目之间进行一些通信。所以;
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 ();
}
}
我们正在使用 Facebook SDK for Unity (v6.0),现在我想知道是否有一种方法可以检查设备上是否安装了 Facebook 应用程序。
原因是 Facebook SDK 中存在错误(参见此处:bug)
我想识别这种情况(仅在安装 FB 应用程序时发生),并做出相应的反应。
"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
所以,基本上你需要在 Objective-C 中编写你的代码,并提供 Unity 和本机代码之间的通信。
检查Facebook APP需要实现的代码是;
(void) checkFacebookApp
{
if ([[UIApplication sharedApplication] canOpenURL:[NSURLURLWithString:@"fb://"]])
{
return true;
}
}
但是您需要在 Unity 和 Xcode 项目之间进行一些通信。所以;
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 ();
}
}