2016-09-19 65 views
2

重构Swift 3后,我有Google Cloud MessagingGCM)这个问题。任何人都可以帮忙吗?无法将类型'(String !, NSError!) - >()'的值转换为期望的参数类型'GGLInstanceIDTokenHandler!'

我得到这个错误: 无法将类型'(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

+0

它看起来像'registrationHandler'的签名已更改。重新输入方法以获得代码完成时的实际签名。 – vadian

+0

@vadian:它显示registrationHandler被depricated :( – Kaptain

+0

然后查看替换的文档。 – vadian

回答

4

重新更改gistrationHandler到

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

这不工作 – Ranjit

+0

@David这并不适用于我 –

1

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

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