gpt4 book ai didi

ios - 确定 Facebook 应用程序是否从 Unity 安装

转载 作者:可可西里 更新时间:2023-11-01 06:06:34 25 4
gpt4 key购买 nike

我们正在使用 Facebook SDK for Unity (v6.0),现在我想知道是否有一种方法可以检查设备上是否安装了 Facebook 应用。

原因是 Facebook SDK 中存在错误(参见此处:bug)

我想识别这种情况(仅在安装 FB 应用程序时发生),并做出相应的 react 。

最佳答案

"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 和 native 代码之间的通信。

检查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 ();
}
}

关于ios - 确定 Facebook 应用程序是否从 Unity 安装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27844180/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com