【问题标题】:Parse Starter kit for Swift 3用于 Swift 3 的 Parse Starter 工具包
【发布时间】:2017-05-05 22:06:26
【问题描述】:

我已经下载了 ParseStarterProject 版本 1.14.3,下载后它要求我转换为 swift 3。之后给我一个错误:

Cannot convert value of type '(Bool, NSError?) -> ()' to expected argument type 'PFBooleanResultBlock?'

代码:

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)
        }
    } as! PFBooleanResultBlock as! PFBooleanResultBlock as! PFBooleanResultBlock as! PFBooleanResultBlock as! PFBooleanResultBlock as! PFBooleanResultBlock as! PFBooleanResultBlock
}

我尝试用另一个线程解决 (AppDelegate.swift function returning errors after converting to swift 3 (cannot convert to PFBooleanResultBlock?)?)

但是给了我这个错误:

 "Expected ) in the expression list"

http://imgur.com/nkdnEZp

【问题讨论】:

标签: swift facebook parse-platform swift3 parse-server


【解决方案1】:

我试图重现相同的错误,我只是将 swift3 生成的代码替换为:

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    let installation = PFInstallation.current()
    installation?.setDeviceTokenFrom(deviceToken)
    installation?.saveInBackground()


    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)
        }
    }

}

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
    if error._code == 3010 {
        print("Push notifications are not supported in the iOS Simulator.\n")
    } else {
        print("application:didFailToRegisterForRemoteNotificationsWithError: %@\n", error)
    }
}

成功了

我的项目是here

【讨论】:

  • 谢谢!!大多数人只是投了反对票,因为他们甚至没有检查 swift 是否再次更改并且有一个新问题并且您解决了它。再次感谢您。
  • @RenatoPimpão 这是真的! ? 没问题,很高兴能解决您的问题
  • Julien,这个简单的“error._code”拯救了我的一天。我已经搜索了如何在任何地方管理 Optional 无济于事。我不得不忽略一个 code=1 值,但拆除那个错误对象似乎很奇怪。为什么 Apple 会做一些简单的事情,比如让 error.code 变得如此困难,这超出了我的理解。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多