2017-05-05 21 views
-1

我已經下載了ParseStarterProject版本1.14.3和下載後,要求我先轉換爲迅速3.之後給我一個錯誤:解析入門套件的斯威夫特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

+0

是作爲7列表! PFBooleanResultBlock'是一個錯字?你爲什麼選擇這種類型? – nathan

+0

這是Xcode自動轉換爲swift 3 ...但即使沒有這個錯字它不起作用。 –

+0

看起來你的確切問題已經在這裏解決:http://stackoverflow.com/a/39684760/6658553 – nathan

回答

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

+0

謝謝!大多數人只是投下了票,因爲他們甚至沒有檢查到迅速改變,並有新的問題,你解決它。再次感謝你。 –

+0

@RenatoPimpão這是真的!沒問題,我很高興解決你的問題 –

+0

Julien,這個簡單的「error._code」剛剛救了我一天。我已經搜索瞭如何管理任何地方的可選無濟於事。我不得不忽略一個代碼= 1的值,但是拆除那個錯誤對象看起來很糟糕。爲什麼Apple做出一些簡單的事情,比如獲取error.code太難了,超出了我的想象。 –