FBSDKGraphRequest 实例方法“-startWithCompletionHandler:”未找到(返回类型默认为“id”)

cle*_*005 5 facebook objective-c ios fbsdk

我不太懂 ObjectiveC 或 iOS,但我正试图用这段代码来解决这个新问题。我将 Facebook SDK pod 更新到 v12.0.0,现在收到此警告:

在以下代码块的最后一行找不到实例方法“-startWithCompletionHandler:”(返回类型默认为“id”)。

    FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:_graphPath
                                                               parameters:arrayParams
                                                               HTTPMethod:_httpMethod];

[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
{
Run Code Online (Sandbox Code Playgroud)

项目将构建并运行,但是当调用此代码时,会发出图形请求,然后引发异常:

因 NSException 类型的未捕获异常而终止 *** 由于未捕获异常“NSInvalidArgumentException”而终止应用程序,原因:“-[FBSDKGraphRequest startWithCompletionHandler:]:无法识别的选择器发送到实例 0x28241b000”

Facebook 官方文档说要这样实现:

   [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
  if (!error) {
     NSLog(@"fetched user:%@", result);
  }
Run Code Online (Sandbox Code Playgroud)

}];

由于未找到 startWithCompletionHandler,xcode 警告仍然存在,并且使用此代码块仍然会引发异常。

任何方向将不胜感激,因为我已经用谷歌搜索自己陷入了昏迷!

cle*_*005 4

好吧,终于找到了正确的谷歌组合并发现:https://github.com/facebook/facebook-ios-sdk/blob/main/FBSDKTVOSKit/FBSDKTVOSKit/FBSDKDeviceLoginViewController.m

这里给出了一个新的startWithCompletion而不是startWithCompletionHandler的例子。

    FBSDKGraphRequest *graphRequest = [[FBSDKGraphRequest alloc] initWithGraphPath:_graphPath
       parameters:arrayParams
       HTTPMethod:_httpMethod];

  [graphRequest startWithCompletion:^(id<FBSDKGraphRequestConnecting> connection, id result, NSError *error) {
Run Code Online (Sandbox Code Playgroud)

感谢@Larme 强调了正确的方向!