Guest User

Untitled

a guest
Jul 16th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. UIApplication.shared.setMinimumBackgroundFetchInterval(30)
  2.  
  3. func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
  4.  
  5. debugPrint("New notification fired from AppDelegate...!!")
  6.  
  7. let notif = UNMutableNotificationContent()
  8. notif.title = "New notification from App delegate"
  9. notif.subtitle = "Cool App!"
  10. notif.body = "I liked it!"
  11.  
  12. UNUserNotificationCenter.current().requestAuthorization(options: [.sound, .badge, .alert], completionHandler: { (isGranted, error) in
  13.  
  14. DispatchQueue.main.async {
  15. let notifTrigger = UNTimeIntervalNotificationTrigger(timeInterval: 0.1, repeats: false)
  16. let request = UNNotificationRequest(identifier: "myNotification", content: notif, trigger: notifTrigger)
  17.  
  18. UNUserNotificationCenter.current().add(request) { (error) in
  19. if error != nil{
  20. print(error!)
  21. } else {
  22. // do something
  23. }
  24. }
  25. }
  26. })
  27.  
  28. }
Add Comment
Please, Sign In to add comment