无法将类型“(String!, NSError!) -> ()”的值转换为预期的参数类型 'GGLInstanceIDTokenHandler!'
Cannot convert value of type '(String!, NSError!) -> ()' to expected argument type 'GGLInstanceIDTokenHandler!'
重构为 Swift 后 Google Cloud Messaging
(GCM
) 出现了这个问题 3. 任何人都可以帮忙吗?
我收到这个错误:
无法将“(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)
}
这是注册处理程序:
func registrationHandler(_ registrationToken: String!, error: NSError!) {
// ...
}
将注册处理程序更改为
func registrationHandler(_ registrationToken: String?, error: Error?) {
// …
}
David 的回答不适用于 Swift 3,很遗憾。但是,这样做:
func registrationHandler(registrationToken: Optional<String>, error: Optional<Error>) {
// ...
}
重构为 Swift 后 Google Cloud Messaging
(GCM
) 出现了这个问题 3. 任何人都可以帮忙吗?
我收到这个错误: 无法将“(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)
}
这是注册处理程序:
func registrationHandler(_ registrationToken: String!, error: NSError!) {
// ...
}
将注册处理程序更改为
func registrationHandler(_ registrationToken: String?, error: Error?) {
// …
}
David 的回答不适用于 Swift 3,很遗憾。但是,这样做:
func registrationHandler(registrationToken: Optional<String>, error: Optional<Error>) {
// ...
}