修复:fbsdk启动bug
This commit is contained in:
parent
d1f51b9245
commit
59ab3b247a
@ -1,14 +1,15 @@
|
||||
package com.funymee.client_proxy_framework
|
||||
|
||||
import android.app.ActivityManager
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import com.facebook.appevents.AppEventsLogger
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import com.facebook.FacebookSdk
|
||||
import io.flutter.embedding.engine.plugins.FlutterPlugin
|
||||
import io.flutter.plugin.common.MethodCall
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
|
||||
/** Facebook App Events:在引擎侧注册固定 Channel,供 Dart 触发 activateApp。 */
|
||||
/** Facebook App Events:在引擎侧注册固定 Channel;等 [FacebookSdk] 初始化完成后再通知 Dart(勿在就绪前调用 AppEventsLogger.activateApp)。 */
|
||||
class ClientProxyFrameworkPlugin : FlutterPlugin, MethodChannel.MethodCallHandler {
|
||||
private var channel: MethodChannel? = null
|
||||
private var deviceMemoryChannel: MethodChannel? = null
|
||||
@ -54,16 +55,33 @@ class ClientProxyFrameworkPlugin : FlutterPlugin, MethodChannel.MethodCallHandle
|
||||
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
|
||||
when (call.method) {
|
||||
"waitForFacebookSdkInit" -> {
|
||||
try {
|
||||
val ctx = applicationContext
|
||||
val app = ctx?.applicationContext as? Application
|
||||
if (app != null) {
|
||||
AppEventsLogger.activateApp(app)
|
||||
if (ctx == null) {
|
||||
result.error("NO_CONTEXT", "applicationContext null", null)
|
||||
return
|
||||
}
|
||||
result.success(true)
|
||||
val mainHandler = Handler(Looper.getMainLooper())
|
||||
try {
|
||||
// SDK 18 无 addInitializedCallback;用 sdkInitialize(..., InitializeCallback) 在就绪后回调
|
||||
//(已初始化时会立即回调)。勿在此处调用 AppEventsLogger.activateApp。
|
||||
@Suppress("DEPRECATION")
|
||||
FacebookSdk.sdkInitialize(
|
||||
ctx.applicationContext,
|
||||
object : FacebookSdk.InitializeCallback {
|
||||
override fun onInitialized() {
|
||||
mainHandler.post {
|
||||
try {
|
||||
channel?.invokeMethod("onFacebookSdkInitialized", null)
|
||||
result.success(true)
|
||||
} catch (e: Exception) {
|
||||
result.error("FB_ACTIVATE_APP", e.message, null)
|
||||
result.error("FB_SDK_READY", e.message, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
result.error("FB_SDK_READY", e.message, null)
|
||||
}
|
||||
}
|
||||
else -> result.notImplemented()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user