我最近将我的应用程序从之前版本的swift转换为swift 3.0(并且还获得了最新版本的Xcode),并且在其他许多错误中,我收到了以下版本:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let installation = PFInstallation.current()
installation.setDeviceTokenFrom(deviceToken)
installation.saveInBackground()
PFPush.subscribeToChannel(inBackground: "") { (succeeded: Bool, error: NSError?) in
if succeeded {
print("ParseStarterProject successfully subscribed to push notifications on the broadcast channel.\n");
} else {
print("ParseStarterProject failed to subscribe to push notifications on the broadcast channel with error = %@.\n", error)
}
}
}
这来自我作为模板下载的SDK(PF指的是Parse框架......我使用的是Heroku托管的Parse服务器)。返回错误说:"无法转换类型的值'(Bool,NSError?) - > ()'预期参数类型' PFBooleanResultBlock?'"
不确定如何解决这个问题。有没有人有任何想法?
答案 0 :(得分:5)
我相信您可以像这样更改您的代码:
PFPush.subscribeToChannel(inBackground: "", block: {(succeeded, error) -> Void in
if succeeded {
print("ParseStarterProject successfully subscribed to push notifications on the broadcast channel.\n");
} else {
print("ParseStarterProject failed to subscribe to push notifications on the broadcast channel with error = %@.\n", error)
}
}
答案 1 :(得分:0)
使用 Swift 3 ,您可以写下:
PFPush.subscribeToChannel(inBackground: "") { (succeeded, error) in
if succeeded {
print("ParseStarterProject successfully subscribed to push notifications on the broadcast channel.\n")
} else {
print("ParseStarterProject failed to subscribe to push notifications on the broadcast channel with error = %@.\n", error)
}
}