无法转换类型'(String!,NSError!)的值 - > ()'预期参数类型' GGLInstanceIDTokenHandler!'

时间:2016-09-19 13:50:00

标签: ios swift google-cloud-messaging

重构到Swift 3后,Google Cloud MessagingGCM)遇到此问题。有人可以帮忙吗?

我收到了这个错误: 无法转换类型'(String!,NSError!)的值 - > ()'预期参数类型' GGLInstanceIDTokenHandler!'

下面:

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

// ...

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

同样的错误:

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

这是registrationHandler:

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

enter image description here

2 个答案:

答案 0 :(得分:4)

将registrationHandler更改为

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

答案 1 :(得分:1)

不幸的是,大卫的答案不适用于Swift 3。但是,这样做:

func registrationHandler(registrationToken: Optional<String>, error: Optional<Error>) {
    // ...
}