ios - Swift with Parse: Error when adding push notification support to appDelegate -
i'm trying add parse appdelegate swift. error saying
cannot invoke 'registerforremotenotifications' argument list of type '(uiusernotificationtype)'
here's code. what's wrong?
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 = uiusernotificationtype.badge | uiusernotificationtype.alert | uiusernotificationtype.sound application.registerforremotenotifications(types) } return true
after you've followed parse tutorial setting push notifications , certificates apple developer console, make sure appdelegate.swift
looks this:
func application(application: uiapplication, didfinishlaunchingwithoptions launchoptions: [nsobject : anyobject]?) -> bool { parse.setapplicationid("id", clientkey:"key") let usernotificationtypes = (uiusernotificationtype.alert | uiusernotificationtype.badge | uiusernotificationtype.sound); let settings = uiusernotificationsettings(fortypes: usernotificationtypes, categories: nil) application.registerusernotificationsettings(settings) application.registerforremotenotifications() return true } func application(application: uiapplication, didregisterforremotenotificationswithdevicetoken devicetoken: nsdata) { // store devicetoken in current installation , save parse let installation = pfinstallation.currentinstallation() installation.setdevicetokenfromdata(devicetoken) installation.adduniqueobject("chat", forkey: "channels") installation.saveinbackground() } func application(application: uiapplication, didfailtoregisterforremotenotificationswitherror error: nserror) { if error.code == 3010 { print("push notifications not supported in ios simulator.") } else { print("application:didfailtoregisterforremotenotificationswitherror: %@", error) } } func application(application: uiapplication, didreceiveremotenotification userinfo: [nsobject : anyobject]) { if application.applicationstate == uiapplicationstate.inactive { pfanalytics.trackappopenedwithremotenotificationpayload(userinfo) } }
this last function resets badge counter when user opens app:
func applicationdidbecomeactive(application: uiapplication) { //reset badge counter 0 var currentinstallation = pfinstallation.currentinstallation() if(currentinstallation.badge != 0){ currentinstallation.badge = 0 } }
Comments
Post a Comment