ios - UILocalNotification not doing anything -
this may seem silly question, first time using uilocalnotification , can't work quick test. doesn't anything.
1. i've created 2 variables in appdelegate
let today = nsdate() let notification: uilocalnotification = uilocalnotification()
2. in applicationdidenterbackground function, have following
notification.firedate = today.datebyaddingtimeinterval(10) notification.alerttitle = "my app test" notification.alertbody = "testing notification \n :)" uiapplication.sharedapplication().presentlocalnotificationnow(notification) uiapplication.sharedapplication().schedulelocalnotification(notification)
3. added applicationdidbecomeactive function
uiapplication.sharedapplication().cancelalllocalnotifications()
after reading documentation again, realized missed crucial first step register app first user notifications. apple doc written in obj-c, able figure out in order convert swift. did:
1. added appdelegate didfinishlaunchingwithoptions function , works
var types: uiusernotificationtype = uiusernotificationtype() types.insert(uiusernotificationtype.alert) types.insert(uiusernotificationtype.badge) let settings: uiusernotificationsettings = uiusernotificationsettings(fortypes: types, categories: nil) uiapplication.sharedapplication().registerusernotificationsettings(settings)
Comments
Post a Comment