0

I am using the Google Calendar API for IOS. I've bridged it so that I can use it in swift. Authorisation works great up until the point that the callback is called (i.e I can see in my Google account the authorisation took place).

In their example they have a selector to handle successful authentication as follows.

// Handle completion of the authorization process, and update the Google Calendar API
// with the new credentials.
- (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController
      finishedWithAuth:(GTMOAuth2Authentication *)authResult
                 error:(NSError *)error {
    //...
}

I have translated this selector as follows...

func finishedAuthorisation(viewController:GTMOAuth2ViewControllerTouch?, authResult:GTMOAuth2Authentication?, error:NSError?){
    //...
}

... and use it like this ...

GTMOAuth2ViewControllerTouch(scope: " ".join(scopes), clientID: kClientID, clientSecret: kClientSecret, keychainItemName: kKeychainItemName, delegate: self, finishedSelector: "finishedAuthorisation:")

... which results in this error

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSInvocation _invocationWithMethodSignature:frame:]: method signature argument cannot be nil'

What am I doing wrong here?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Chris
  • 7,996
  • 11
  • 66
  • 98
  • Read [this nice answer](http://stackoverflow.com/a/24007718/581190) and [this](https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithObjective-CAPIs.html#//apple_ref/doc/uid/TP40014216-CH4-XID_26) - scroll down to Objective-C Selectors. – zrzka Jul 13 '15 at 14:04

2 Answers2

1

I solved it by using this selector finishedAuthorisation:authResult:error:

In practice:

The handling method:

func finishedAuthorisation(viewController:GTMOAuth2ViewControllerTouch, authResult:GTMOAuth2Authentication, error:NSError?) {
    ...
}

And how I used the selector:

GTMOAuth2ViewControllerTouch(scope: " ".join(scopes), clientID: kClientID, clientSecret: kClientSecret, keychainItemName: kKeychainItemName, delegate: self, finishedSelector: "finishedAuthorisation:authResult:error:")
Chris
  • 7,996
  • 11
  • 66
  • 98
0

Your finishedAuthorisation selector takes three arguments. Try putting three colons : "finishedAuthorisation:::"

ryancrunchi
  • 465
  • 2
  • 16