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!) {
// ...
}
Change registrationHandler to
func registrationHandler(_ registrationToken: String?, error: Error?) {
// …
}
David's answer doesn't work with Swift 3, unfortunately. However, this does:
func registrationHandler(registrationToken: Optional<String>, error: Optional<Error>) {
// ...
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.