Search code examples
swiftfacebookparse-platformswift3parse-server

Parse Starter kit for Swift 3


I've downloaded the ParseStarterProject version 1.14.3 and after download it asks me to convert to swift 3. After that gives me an error:

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

Code:

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
}

I tried solving with another thread (AppDelegate.swift function returning errors after converting to swift 3 (cannot convert to PFBooleanResultBlock?)?)

But gives me this error:

 "Expected ) in the expression list"

http://imgur.com/nkdnEZp


Solution

  • I've tried to reproduce the same bug, I just replace the swift3 generated code with:

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

    An it works

    My project is here