每当应用收到动作响应时,我想在AppDelegate.swift中访问我的应用程序数据.我试图使用
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
if response.actionIdentifier == "check" {
//do something to the app's data
}
completionHandler()
}
Run Code Online (Sandbox Code Playgroud)
方法,但我找不到数据,因为我无法获取通知的标识符或其正文.有人可以帮助我吗?非常感谢你们.
更多代码:
//Setting content of the notification
let content = UNMutableNotificationContent()
content.title = "Scheduled Task"
content.body = taskDescriptionTextField.text!
content.badge = 1
content.sound = UNNotificationSound.default()
content.categoryIdentifier = "alertCategory"
//Setting time for notification trigger
let date = datePicker.date
let dateCompenents = Calendar.current.dateComponents([.year,.month,.day,.hour,.minute,.second], from: date)
let trigger = UNCalendarNotificationTrigger(dateMatching: dateCompenents, repeats: false)
//Adding Request …Run Code Online (Sandbox Code Playgroud) 谁能告诉我如何在 UIActivityViewController 中实现“在 Safari 中打开”?我知道这个问题是很久以前发布的另一个问题的重复,当时的方法是使用不再使用的框架。
我共享的数据是一个 URL。我已经有一个完全可用的 ActivityVC,我只需要添加“在 safari 中打开”按钮。
非常感谢。
代码:
@IBAction func shareButtonPressed(_ sender: UIButton) {
let activityVC = UIActivityViewController(activityItems: [URL(string: urlStr)!], applicationActivities: nil)
activityVC.popoverPresentationController?.sourceView = self.view
self.present(activityVC, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)