3

I'm not ObjectiveC savvy or iOS savvy but I'm trying to muddle through this new issue with this code. I updated the Facebook SDK pod to v12.0.0 and now I'm getting this warning :

Instance method '-startWithCompletionHandler:' not found (return type defaults to 'id') on the last line of the following code block.

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

[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
{

Project will build and run, but when this code is called the graph request is made and then it throws an exception :

terminating with uncaught exception of type NSException *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FBSDKGraphRequest startWithCompletionHandler:]: unrecognized selector sent to instance 0x28241b000'

Official Facebook Docs say to implement like this :

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

}];

The xcode warning is still there for startWithCompletionHandler not being found and the exception still gets thrown using this code block.

Any direction would be greatly appreciated as I've Googled myself into a stupor!

clee2005
  • 127
  • 1
  • 5
  • According to the doc of the repo, since the one online seems outdated: `Added startWithCompletion: to FBSDKGraphRequest. Replaces startWithCompletionHandler:`. Remove the call, and let autocompletion help you if needed. Seen on changelog: https://github.com/facebook/facebook-ios-sdk/blob/main/CHANGELOG.md – Larme Jan 27 '22 at 16:06
  • Thanks, yes I saw that and tried to use only startWithCompletion instead of startWithCompletionHandler, but it didn't like that either. I got the same exception. – clee2005 Jan 27 '22 at 17:01
  • It shouldn't, since the method exists in last version. Is it really your code that creates it, or another lib? I saw that other libs might still call it: https://github.com/facebook/facebook-ios-sdk/issues/1978 – Larme Jan 27 '22 at 17:07
  • I'm sorry, I was wrong that it was the same for startWithCompletion! I wasn't able to figure out the syntax required for this as it seems to be different. Simply replacing startWithCompletionHandler with startWithCompletion creates all sorts of unhappiness in Xcode. Cannot initialize a parameter of type 'FBSDKGraphRequestCompletion _Nullable' (aka 'void (^)(id _Nullable, id _Nullable, NSError * _Nullable)') with an rvalue of type 'void (^)(FBSDKGraphRequestConnection *, id, NSError *)' – clee2005 Jan 27 '22 at 17:31
  • Why is there no official Facebook sample using startWithCompletion only in place of the old startWithCompletionHandler? I cannot find an example anywhere. – clee2005 Jan 27 '22 at 17:54

1 Answers1

2

Ok finally hit the right Google combination and found : https://github.com/facebook/facebook-ios-sdk/blob/main/FBSDKTVOSKit/FBSDKTVOSKit/FBSDKDeviceLoginViewController.m

Here it gives an example of the new startWithCompletion instead of startWithCompletionHandler.

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

  [graphRequest startWithCompletion:^(id<FBSDKGraphRequestConnecting> connection, id result, NSError *error) {

Thanks @Larme for highlighting the right direction!

clee2005
  • 127
  • 1
  • 5