Kaptain Kaptain - 2 months ago 125
iOS Question

Cannot convert value of type '(String!, NSError!) -> ()' to expected argument type 'GGLInstanceIDTokenHandler!'

I have this problem with

Google Cloud Messaging
(
GCM
) after refactoring to Swift 3. Can anyone help?

I got this error:
Cannot convert value of type '(String!, NSError!) -> ()' to expected argument type 'GGLInstanceIDTokenHandler!'

Here:

func application( _ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data ) {

// ...

GGLInstanceID.sharedInstance().tokenWithAuthorizedEntity(gcmSenderID, scope: kGGLInstanceIDScopeGCM, options: registrationOptions, handler: registrationHandler)
}


And same error here:

func onTokenRefresh() {
GGLInstanceID.sharedInstance().token(withAuthorizedEntity: gcmSenderID, scope: kGGLInstanceIDScopeGCM, options: registrationOptions, handler: registrationHandler)
}


This is the registrationHandler:

func registrationHandler(_ registrationToken: String!, error: NSError!) {
// ...
}


enter image description here

Answer

Change registrationHandler to

func registrationHandler(_ registrationToken: String?, error: Error?) {
    // …
}