Created
November 1, 2016 15:24
-
-
Save Melonbwead/d519c2e85616c6d6c265c7969df8d17a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if #available(iOS 10.0, *) { | |
let content = UNMutableNotificationContent() | |
content.title = "🔧Service is due in 2 Days🔧" | |
content.subtitle = "\(carReg)" | |
content.body = "🚗 \(carReg) service is due on 7th Nov." | |
content.sound = UNNotificationSound.default() | |
content.categoryIdentifier = "io.swifting.notification-request" | |
let defaults = UserDefaults.standard | |
defaults.set("\(carReg)", forKey: "userReg") | |
let bookServiceAction = UNNotificationAction(identifier:"bookService", title:"Book A Service", options:[.foreground]) | |
let dismissAction = UNNotificationAction(identifier:"dismiss", title:"Dismiss", options:[]) | |
let category = UNNotificationCategory( | |
identifier: "io.swifting.notification-request", | |
actions: [bookServiceAction, dismissAction], | |
intentIdentifiers: [], | |
options: []) | |
let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 5, repeats: false) | |
let request = UNNotificationRequest.init(identifier: "FiveSecond", content: content, trigger: trigger) | |
let center = UNUserNotificationCenter.current() | |
center.setNotificationCategories([category]) | |
center.add(request) { (error) in | |
print("errored!!") | |
print(error) | |
print(request) | |
} | |
} else { | |
// Fallback on earlier versions | |
let notification = UILocalNotification() | |
let dict:NSDictionary = ["ID" : "your ID goes here"] | |
notification.userInfo = dict as! [String : String] | |
notification.alertBody = "\(title)" | |
notification.alertAction = "Open" | |
notification.fireDate = NSDate(timeIntervalSinceNow: 15) as Date | |
notification.soundName = UILocalNotificationDefaultSoundName | |
UIApplication.shared.scheduleLocalNotification(notification) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment