Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. override func viewDidLoad() {
  2. super.viewDidLoad()
  3. // Do any additional setup after loading the view, typically from a nib.
  4. askForPermission()
  5. }
  6.  
  7. @IBAction func addLocalNotification(_ sender: AnyObject) {
  8.  
  9. addLocalNotification()
  10. }
  11.  
  12. func addLocalNotification() {
  13.  
  14. let content = UNMutableNotificationContent()
  15. content.title = "iOS10.0"
  16. content.body = "Hello Buddy"
  17. content.sound = UNNotificationSound.default()
  18. // Deliver the notification in five seconds.
  19. let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 5, repeats: false)
  20. let request = UNNotificationRequest.init(identifier: "FiveSecond", content: content, trigger: trigger)
  21. // Schedule the notification.
  22. let center = UNUserNotificationCenter.current()
  23. center.add(request) { (error) in
  24. print(error)
  25. }
  26. print("should have been added")
  27. }
  28.  
  29. func askForPermission() {
  30.  
  31. UNUserNotificationCenter.current().requestAuthorization(options: [.alert,.sound,.badge]) { (granted, error) in
  32.  
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement