代码之家  ›  专栏  ›  技术社区  ›  Kaptain

无法转换“(String!,NSError!)->”类型的值()'应为参数类型“GGLInstanceIDTokenHandler!”

  •  2
  • Kaptain  · 技术社区  · 8 年前

    我有这个问题 Google Cloud Messaging ( GCM )在重构为Swift 3之后。有人能帮忙吗?

    我得到了这个错误:

    在这里:

    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!) {
        // ...
    }
    

    enter image description here

    2 回复  |  直到 8 年前
        1
  •  4
  •   David    8 年前

    将registrationHandler更改为

    func registrationHandler(_ registrationToken: String?, error: Error?) {
        // …
    }
    
        2
  •  1
  •   Colin    8 年前

    不幸的是,David的回答不适用于Swift 3。然而,这确实:

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