client_framework/ios/Classes/ClientProxyFrameworkPlugin.swift
2026-04-16 17:00:55 +08:00

69 lines
2.4 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Flutter
import UIKit
import FBSDKCoreKit
import os.log
public class ClientProxyFrameworkPlugin: NSObject, FlutterPlugin {
private var channel: FlutterMethodChannel?
public static func register(with registrar: FlutterPluginRegistrar) {
let ch = FlutterMethodChannel(
name: "client_proxy_framework/facebook_sdk",
binaryMessenger: registrar.messenger())
let instance = ClientProxyFrameworkPlugin()
instance.channel = ch
registrar.addMethodCallDelegate(instance, channel: ch)
}
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
switch call.method {
case "setFacebookSdkDebugLogging":
let args = call.arguments as? [String: Any]
let enabled = Self.coerceFacebookSdkDebugLogsArg(args?["enabled"])
Self.applyFacebookSdkDebugLogging(enabled: enabled)
result(nil)
case "waitForFacebookSdkInit":
let args = call.arguments as? [String: Any]
let debugLogs = Self.coerceFacebookSdkDebugLogsArg(args?["facebookSdkDebugLogs"])
Self.applyFacebookSdkDebugLogging(enabled: debugLogs)
result(true)
channel?.invokeMethod("onFacebookSdkInitialized", arguments: nil)
default:
result(FlutterMethodNotImplemented)
}
}
/// Android `facebook.debugLogs` Dart `setFacebookSdkDebugLogging`
private static func applyFacebookSdkDebugLogging(enabled: Bool) {
if enabled {
Settings.shared.loggingBehaviors = Set([
.appEvents,
.networkRequests,
.informational,
.developerErrors,
.graphAPIDebugInfo,
])
os_log("Facebook SDK debug logging ON (filter console for FBSDK / Facebook)", log: .default, type: .info)
print("ClientProxyFB: Facebook SDK debug logging ON — also search Xcode console for FBSDK / FacebookSDK")
} else {
Settings.shared.loggingBehaviors = []
os_log("Facebook SDK debug logging OFF", log: .default, type: .info)
print("ClientProxyFB: Facebook SDK debug logging OFF")
}
}
private static func coerceFacebookSdkDebugLogsArg(_ raw: Any?) -> Bool {
switch raw {
case let b as Bool:
return b
case let n as NSNumber:
return n.intValue != 0
case let s as String:
let v = s.trimmingCharacters(in: .whitespacesAndNewlines).lowercased()
return v == "true" || v == "1" || v == "yes"
default:
return false
}
}
}