Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- import UserNotifications
- class ViewController: UIViewController {
- override func viewDidLoad() {
- super.viewDidLoad()
- // Setup after loading the view
- // Ask for permission
- let center = UNUserNotificationCenter.current()
- center.requestAuthorization(options: [.alert, .sound]) { (granted, error) in
- // Create the notification content
- let content = UNMutableNotificationContent()
- content.title = "Hey I'm a notifcation!"
- content.body = "Look at me!"
- // Create the notification trigger
- let date = Date().addingTimeInterval(5)
- let dateComponents = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute, .second], from: date)
- let trigger = UNNotificationRequest(identifier: uuid_string_t, content: content, trigger: trigger)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement