如何以编程方式禁用Facebook无代码事件?

问题描述 投票:8回答:1

Problem

几个月我们有一个实时应用程序运行良好,然后突然这个代码破了:

ViewController.swift

self.tableView.delegate = self.viewModel.tableViewHandler

使用此代码

Broken code

component.swift

public override weak var delegate: UITableViewDelegate? {
     get { return super.delegate }
     set {
         if let del = newValue as? TableViewDelegateProxy {
             super.delegate = del
         } else if let del = super.delegate as? TableViewDelegateProxy {
             del.targetDelegate = newValue
         } else {
             super.delegate = newValue
         }
     }
 }

我们无法弄清楚原因,但我们用这段代码修复了它:

Fixed code

ViewController.swift

self.tableView.fixedDelegate = self.viewModel.tableViewHandler

component.swift

// IMPORTANT NOTE: That is the correct way to set a delegate,
//                 otherwise overriding `delegate` property fails
public var fixedDelegate: UITableViewDelegate? {
    get { return self.delegate }
    set {
        self.delegateProxy.targetDelegate = newValue
        self.delegate = self.delegateProxy
    }
}

最初我们认为这是来自后端的问题(格式错误的JSON或类似的东西),但后来我们意识到以下几点:

  • 使用调试配置编译时,损坏的代码有效,但在使用版本配置时会中断
  • 使用调试配置编译时,固定代码有效,使用版本配置时也可以使用

我们在Git历史中跳过了许多版本,并且总是如此,这让我们相信我们的Xcode或Objc / Swift运行时库可能会有一些变化,这会导致这种奇怪现象。

Question

我们的Xcode IDE可以改变什么来解释这个?它可以是远程或幕后变化的东西吗?我们怎样才能进一步调试呢?

References

1)Xcode版本:10.1版(10B61) 2)Swift版本:

xcrun swift -version
Apple Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1)
Target: x86_64-apple-darwin18.2.0

3)obj-c库:

 otool -L /usr/lib/libobjc.A.dylib
/usr/lib/libobjc.A.dylib:
        /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
        /usr/lib/libc++abi.dylib (compatibility version 1.0.0, current version 400.17.0)
        /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.4)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.200.5)

Update

首先看看这个answer,我们需要以编程方式关闭this标志

_serverConfiguration.isCodelessEventsEnabled

不确定如何从sdk(Android或iOS)

我们尝试了什么

1)我们无法通过FB SDK找到任何方法,比如这个:https://developers.facebook.com/docs/reference/androidsdk/current/facebook/com/facebook/facebooksdk.html/

2)我们尝试通过curl逆向工程联系FB API,它适用于电子邮件等场景:

curl --header "Content-Type: application/json" \
  --request POST \
  --data '{"app_events_feature_bitmask":0}' \
  "https://graph.facebook.com/***?access_token=<app_secret>"

它归还了这个

{"success":true}

但对于应用事件功能没有任何改变:

curl -i -X GET "https://graph.facebook.com/***?fields=app_events_feature_bitmask&access_token=<app_secret>"

它返回旧值:

{"app_events_feature_bitmask":37,"id":"***"}

3)ask FB tech support

ios objective-c swift xcode
1个回答
6
投票

事实证明这是一些facebook远程配置的东西,如果我们注释掉this code

  //  UITableView
  void (^tableViewBlock)(UITableView *tableView,
                         SEL cmd,
                         id<UITableViewDelegate> delegate) =
  ^(UITableView *tableView, SEL cmd, id<UITableViewDelegate> delegate) {
    if (!delegate) {
      return;
    }

    [self matchView:tableView delegate:delegate];
  };
  [FBSDKSwizzler swizzleSelector:@selector(setDelegate:)
                         onClass:[UITableView class]
                       withBlock:tableViewBlock
                           named:@"match_table_view"];

它工作得很好。一旦这个标志是turned on,这个功能似乎就会打开:

#if !TARGET_OS_TV
- (void)enableCodelessEvents {
  if (_serverConfiguration.isCodelessEventsEnabled) { <-----
    if (!_eventBindingManager) {
      _eventBindingManager = [[FBSDKEventBindingManager alloc] init];
    }

    if ([FBSDKInternalUtility isUnity]) {
      [FBSDKAppEvents sendEventBindingsToUnity];
    } else {
      [_eventBindingManager updateBindings:[FBSDKEventBindingManager
                                            parseArray:_serverConfiguration.eventBindings]];
    }
  }
}
#endif

问题是:什么打开了这面旗帜? (即从一些fb远程配置)

_serverConfiguration.isCodelessEventsEnabled

这就是我们想要找到的东西

update: short answer: you cannot (programmatically, via dashboard, or even by contacting fb support themselves)

Facebook技术支持回到我身边,用简单的英语说明这个选项根本不可能:

enter image description here

长话短说:通过安装FB App Events SDK,您将自动打开启用无代码事件的FB远程配置,并且无法将其关闭。

Conclusion

我们能够重现问题(具体来说,通过在Facebook管理员上执行几个步骤打开fb远程事件标志)

首先运行一个示例应用程序并测试该标志是否打开/关闭:

enter image description here

转到事件管理器并单击+添加新数据源>应用程序事件

enter image description here

enter image description here

enter image description here

当你点击那个按钮时,你会看到这个

enter image description here

这就是国旗开启的时候!

© www.soinside.com 2019 - 2024. All rights reserved.