重构到Swift 3后,Google Cloud Messaging
(GCM
)遇到此问题。有人可以帮忙吗?
我收到了这个错误: 无法转换类型'(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!) {
// ...
}
答案 0 :(得分:4)
将registrationHandler更改为
func registrationHandler(_ registrationToken: String?, error: Error?) {
// …
}
答案 1 :(得分:1)
func registrationHandler(registrationToken: Optional<String>, error: Optional<Error>) {
// ...
}