Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AppDelegate: UIResponder, UIApplicationDelegate {
- var window: UIWindow?
- func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
- let notificationType = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound
- let settings = UIUserNotificationSettings(forTypes: notificationType, categories: nil)
- application.registerUserNotificationSettings(settings)
- application.applicationIconBadgeNumber = 0 // resetting the badge number to again 0
- return true
- }
- func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {
- application.applicationIconBadgeNumber = 0 //resetting the badge number to again 0
- }
- class ViewController: UIViewController {
- @IBAction func startNotification(sender: UIButton) {
- var localNotification = UILocalNotification()
- localNotification.fireDate = NSDate(timeIntervalSinceNow: 5) // notification will be sent after 5 seconds from clicking
- localNotification.alertBody = "Notification came"
- localNotification.timeZone = NSTimeZone.defaultTimeZone() // Time zone of the notfication's fire date
- localNotification.applicationIconBadgeNumber = UIApplication.sharedApplication().applicationIconBadgeNumber + 1 //The number to diplay on the icon badge. We will increment this number by one.
- UIApplication.sharedApplication().scheduleLocalNotification(localNotification) // scheduling the notification
- }
Add Comment
Please, Sign In to add comment