baxi há 6 dias atrás
pai
commit
e80912876c
2 ficheiros alterados com 17 adições e 3 exclusões
  1. 7 0
      native/engine/ios/FACEBOOK.md
  2. 10 3
      native/engine/ios/service/FBWrapper.mm

+ 7 - 0
native/engine/ios/FACEBOOK.md

@@ -33,6 +33,13 @@ SDK 中 Swift 实现的登录类、分享协议通过这些生成头文件暴露
 仅修改 .mm 导入后无需重新安装 Pods;在 Xcode 执行 Product → Clean Build Folder 后重新 Build。
 若报的是 `-Swift.h file not found`,则检查 Pods 安装、应用 target 和 workspace 是否匹配。
 
+## JsbBridgeWrapper 回调崩溃
+
+Creator 3.8.8 的 `addScriptEventListener:listener:` 使用 MRC,保存 listener 后会调用 `[listener release]`。
+FBWrapper 的注册入口使用不捕获 self 或局部变量的全局 Block,避免临时 Block 的生命周期与引擎所有权处理不匹配。
+不要将该入口改回捕获 self 的匿名 Block;在回调内通过 `[FBWrapper shared]` 获取实例。
+同步 FBWrapper.mm 后重新编译,在真机验证初始化、登录和事件调用。此修复无需修改 Creator 安装目录中的引擎源码。
+
 ## 登录结果与后端
 
 默认使用 Limited Login,不主动请求 ATT,不开启广告追踪。

+ 10 - 3
native/engine/ios/service/FBWrapper.mm

@@ -33,9 +33,16 @@
 
 - (void)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)options {
     // Register even on configuration failure so JS receives a useful error instead of timing out.
-    [[JsbBridgeWrapper sharedInstance] addScriptEventListener:@"facebook.request" listener:^(NSString *payload) {
-        dispatch_async(dispatch_get_main_queue(), ^{ [self handlePayload:payload]; });
-    }];
+    // Creator 3.8.8's MRC bridge releases the listener after adding it to its array.
+    // Keep this outer block capture-free (no self or local variables): a global block
+    // has static lifetime and is safe with that ownership behavior. GCD owns the
+    // inner block and retains its payload until the main-queue callback runs.
+    static OnScriptEventListener const requestListener = ^(NSString *payload) {
+        dispatch_async(dispatch_get_main_queue(), ^{
+            [[FBWrapper shared] handlePayload:payload];
+        });
+    };
+    [[JsbBridgeWrapper sharedInstance] addScriptEventListener:@"facebook.request" listener:requestListener];
     NSDictionary *info = NSBundle.mainBundle.infoDictionary;
     if (![info[@"FacebookAppID"] isKindOfClass:NSString.class] || ![info[@"FacebookAppID"] length] ||
         ![info[@"FacebookClientToken"] isKindOfClass:NSString.class] || ![info[@"FacebookClientToken"] length]) {