Guest User

Untitled

a guest
Aug 28th, 2015
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. class AppDelegate: UIResponder, UIApplicationDelegate {
  2.  
  3. var window: UIWindow?
  4.  
  5. func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
  6.  
  7. let notificationType = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound
  8. let settings = UIUserNotificationSettings(forTypes: notificationType, categories: nil)
  9. application.registerUserNotificationSettings(settings)
  10.  
  11. application.applicationIconBadgeNumber = 0 // resetting the badge number to again 0
  12.  
  13. return true
  14. }
  15.  
  16. func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {
  17.  
  18. application.applicationIconBadgeNumber = 0 //resetting the badge number to again 0
  19.  
  20. }
  21.  
  22. class ViewController: UIViewController {
  23.  
  24.  
  25. @IBAction func startNotification(sender: UIButton) {
  26.  
  27. var localNotification = UILocalNotification()
  28. localNotification.fireDate = NSDate(timeIntervalSinceNow: 5) // notification will be sent after 5 seconds from clicking
  29. localNotification.alertBody = "Notification came"
  30. localNotification.timeZone = NSTimeZone.defaultTimeZone() // Time zone of the notfication's fire date
  31. localNotification.applicationIconBadgeNumber = UIApplication.sharedApplication().applicationIconBadgeNumber + 1 //The number to diplay on the icon badge. We will increment this number by one.
  32.  
  33. UIApplication.sharedApplication().scheduleLocalNotification(localNotification) // scheduling the notification
  34.  
  35. }
Add Comment
Please, Sign In to add comment