ios - saving objects to parse -
i'm still new ios development have knowledge of swift language, i'm trying learn how save objects parse, after created app on parse , downloaded xcode swift template parse , pasted application id & cleint-key appdelegate.swift file , add save file code parse viewcontroller file , tried run app, got error in appdelegate.swift : please check link below view error: http://i.gyazo.com/9ef2283ab1db616d4f8a13350482cbfd.png
// // appdelegate.swift // // copyright 2011-present parse inc. rights reserved. // import uikit import bolts import parse // if want use of ui components, uncomment line // import parseui // if want use crash reporting - uncomment line // import parsecrashreporting @uiapplicationmain class appdelegate: uiresponder, uiapplicationdelegate { var window: uiwindow? //-------------------------------------- // mark: - uiapplicationdelegate //-------------------------------------- func application(application: uiapplication, didfinishlaunchingwithoptions launchoptions: [nsobject: anyobject]?) -> bool { parse.setapplicationid("s4evmuoptdrwk7cxkfgfgax09vbdcwowx1v51wcd", clientkey: "y7vxfm1q4boria599stucncifghgiooekbun7n00") parse.enablelocaldatastore() // **************************************************************************** // uncomment line if want enable crash reporting // parsecrashreporting.enable() // // uncomment , fill in parse credentials: // parse.setapplicationid("your_application_id", clientkey: "your_client_key") // // if using facebook, uncomment , add facebookappid bundle's plist // described here: https://developers.facebook.com/docs/getting-started/facebook-sdk-for-ios/ // uncomment line inside parsestartproject-bridging-header , following line here: // pffacebookutils.initializefacebook() // **************************************************************************** pfuser.enableautomaticuser() let defaultacl = pfacl(); // if objects private default, remove line. defaultacl.setpublicreadaccess(true) pfacl.setdefaultacl(defaultacl, withaccessforcurrentuser:true) if application.applicationstate != uiapplicationstate.background { // track app open here if launch push, unless // "content_available" used trigger background push (introduced in ios 7). // in case, skip tracking here avoid double counting app-open. let prebackgroundpush = !application.respondstoselector("backgroundrefreshstatus") let oldpushhandleronly = !self.respondstoselector("application:didreceiveremotenotification:fetchcompletionhandler:") var nopushpayload = false; if let options = launchoptions { nopushpayload = options[uiapplicationlaunchoptionsremotenotificationkey] != nil; } if (prebackgroundpush || oldpushhandleronly || nopushpayload) { pfanalytics.trackappopenedwithlaunchoptions(launchoptions) } } if application.respondstoselector("registerusernotificationsettings:") { let usernotificationtypes = uiusernotificationtype.alert | uiusernotificationtype.badge | uiusernotificationtype.sound let settings = uiusernotificationsettings(fortypes: usernotificationtypes, categories: nil) application.registerusernotificationsettings(settings) application.registerforremotenotifications() } else { let types = uiremotenotificationtype.badge | uiremotenotificationtype.alert | uiremotenotificationtype.sound application.registerforremotenotificationtypes(types) } return true } //-------------------------------------- // mark: push notifications //-------------------------------------- func application(application: uiapplication, didregisterforremotenotificationswithdevicetoken devicetoken: nsdata) { let installation = pfinstallation.currentinstallation() installation.setdevicetokenfromdata(devicetoken) installation.saveinbackground() pfpush.subscribetochannelinbackground("", block: { (succeeded: bool, error: nserror!) -> void in if succeeded { println("parsestarterproject subscribed push notifications on broadcast channel."); } else { println("parsestarterproject failed subscribe push notifications on broadcast channel error = %@.", error) } }) } func application(application: uiapplication, didfailtoregisterforremotenotificationswitherror error: nserror) { if error.code == 3010 { println("push notifications not supported in ios simulator.") } else { println("application:didfailtoregisterforremotenotificationswitherror: %@", error) } } func application(application: uiapplication, didreceiveremotenotification userinfo: [nsobject : anyobject]) { pfpush.handlepush(userinfo) if application.applicationstate == uiapplicationstate.inactive { pfanalytics.trackappopenedwithremotenotificationpayload(userinfo) } } /////////////////////////////////////////////////////////// // uncomment method if want use push notifications background app refresh /////////////////////////////////////////////////////////// // func application(application: uiapplication, didreceiveremotenotification userinfo: [nsobject : anyobject], fetchcompletionhandler completionhandler: (uibackgroundfetchresult) -> void) { // if application.applicationstate == uiapplicationstate.inactive { // pfanalytics.trackappopenedwithremotenotificationpayload(userinfo) // } // } //-------------------------------------- // mark: facebook sdk integration //-------------------------------------- /////////////////////////////////////////////////////////// // uncomment method if using facebook /////////////////////////////////////////////////////////// // func application(application: uiapplication, openurl url: nsurl, sourceapplication: string?, annotation: anyobject?) -> bool { // return fbappcall.handleopenurl(url, sourceapplication:sourceapplication, session:pffacebookutils.session()) // } }
//************************
and viewcontroller.swift used code :
import uikit import parse
class viewcontroller: uiviewcontroller {
override func viewdidload() { super.viewdidload() var gamescore = pfobject(classname:"gamescore") gamescore["score"] = 1337 gamescore["playername"] = "sean plott" gamescore["cheatmode"] = false gamescore.saveinbackgroundwithblock { (success: bool, error: nserror?) -> void in if (success) { // object has been saved. } else { // there problem, check error.description } } } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. }
}
parse has documentation , here can find how save objects. switch programming language swift.
as error getting seems have parameter. if want handle response block should using method: + subscribetochannelinbackground:block:
. reference can read documentation.
edit: try nserror?
instead of nserror!
. should have this:
pfpush.subscribetochannelinbackground("", block: { (succeeded: bool, error: nserror?) -> void in if succeeded { println("parsestarterproject subscribed push notifications on broadcast channel."); } else { println("parsestarterproject failed subscribe push notifications on broadcast channel error = %@.", error) } })
Comments
Post a Comment