Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. import UIKit
  2. import UserNotifications
  3.  
  4. class ViewController: UIViewController {
  5.  
  6. override func viewDidLoad() {
  7. super.viewDidLoad()
  8. // Setup after loading the view
  9.  
  10. // Ask for permission
  11. let center = UNUserNotificationCenter.current()
  12.  
  13. center.requestAuthorization(options: [.alert, .sound]) { (granted, error) in
  14.  
  15.  
  16. // Create the notification content
  17. let content = UNMutableNotificationContent()
  18. content.title = "Hey I'm a notifcation!"
  19. content.body = "Look at me!"
  20.  
  21. // Create the notification trigger
  22. let date = Date().addingTimeInterval(5)
  23.  
  24. let dateComponents = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute, .second], from: date)
  25.  
  26. let trigger = UNNotificationRequest(identifier: uuid_string_t, content: content, trigger: trigger)
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement