मैंने दो कार्यों के साथ एक अधिसूचना बनाई। मेरे कार्यों में से एक को "रद्द करें" कहा जाता है, जबकि दूसरे को "कॉल" कहा जाता है। मैं "कॉल" एक्शन को एक यूआरएल कैसे चला सकता हूं जो एक टिप्पणी में है जिसे मैंने अपने कोड में जोड़ा है।एक यूआरएल कैसे चलाएं जब अधिसूचना कार्रवाई दबाई जाती है?
func notificationFires(){
/**
URL Code:
if let url = URL(string: "tel://") {
UIApplication.shared.open(url, options: [:])
}
**/
let call = UNNotificationAction(identifier:"call", title:"Call", options:[.foreground])
let cancel = UNNotificationAction(identifier: "cancel", title: "Cancel", options: [.destructive ])
let category = UNNotificationCategory(identifier: "category", actions: [call, cancel], intentIdentifiers: [], options: [])
UNUserNotificationCenter.current().setNotificationCategories([category])
let notification = UILocalNotification()
notification.category = "category"
// 2
notification.soundName = UILocalNotificationDefaultSoundName
notification.fireDate = datePicker.date
// 3
if textField.text == "" {
notification.alertBody = "You have a call right now!"
}
else{
notification.alertBody = self.textField.text
}
// 4
notification.timeZone = NSTimeZone.default
// 5
// 6
notification.applicationIconBadgeNumber = 1
// 7
func application(application: UIApplication!, handleActionWithIdentifier identifier:String!, forLocalNotification notification:UILocalNotification!, completionHandler: (() -> Void)!){
if (identifier == "call"){
if let url = URL(string: "tel://2162964785") {
UIApplication.shared.open(url, options: [:])
}
}else if (identifier == "cancel"){
}
}
UIApplication.shared.scheduleLocalNotification(notification)
func application(application: UIApplication, didReceiveLocalNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
print("Recieved: notification")
let center = UNUserNotificationCenter.current()
center.removeDeliveredNotifications(withIdentifiers: ["notification"])
}
}
शायद निम्नलिखित मददगार होगा http://useyourloaf.com/blog/openurl-deprecated-in-ios10/ https://stackoverflow.com/questions/38964264/openurl-in-ios10?rq=1 – CuriousRabbit