0
私はローカル通知を受け取り、それにアクションを追加しました。アクションをタップすると、15分後にローカル通知が再開されるように、どうすればよいですか?iOS 10でのローカル通知の延期
extension UNNotificationAttachment {
static func create(identifier: String, image: UIImage, options: [NSObject : AnyObject]?) -> UNNotificationAttachment? {
let fileManager = FileManager.default
let tmpSubFolderName = ProcessInfo.processInfo.globallyUniqueString
let tmpSubFolderURL = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(tmpSubFolderName, isDirectory: true)
do {
try fileManager.createDirectory(at: tmpSubFolderURL, withIntermediateDirectories: true, attributes: nil)
let imageFileIdentifier = identifier+".png"
let fileURL = tmpSubFolderURL.appendingPathComponent(imageFileIdentifier)
guard let imageData = UIImagePNGRepresentation(image) else {
return nil
}
try imageData.write(to: fileURL)
let imageAttachment = try UNNotificationAttachment.init(identifier: imageFileIdentifier, url: fileURL, options: options)
return imageAttachment
} catch {
print("error " + error.localizedDescription)
}
return nil
}
}
func scheduleNotification() {
removeNotification()
if shouldRemind && dueDate > Date() {
let content = UNMutableNotificationContent()
content.title = "Reminder:"
content.body = text
content.sound = UNNotificationSound.default()
let calendar = Calendar(identifier: .gregorian)
let components = calendar.dateComponents([.month, .day, .hour, .minute], from: dueDate)
let trigger = UNCalendarNotificationTrigger(dateMatching: components, repeats: false)
let identifier = ProcessInfo.processInfo.globallyUniqueString
if let attachment = UNNotificationAttachment.create(identifier: identifier, image: notificationImage, options: nil) {
content.attachments = [attachment]
}
let action = UNNotificationAction(identifier: "remindLater", title: "Remind me later", options: [])
let category = UNNotificationCategory(identifier: "category", actions: [action], intentIdentifiers: [], options: [])
UNUserNotificationCenter.current().setNotificationCategories([category])
content.categoryIdentifier = "category"
let request = UNNotificationRequest(identifier: "\(itemID)", content: content, trigger: trigger)
let center = UNUserNotificationCenter.current()
center.add(request)
}
}
私はこれを考えましたが、アプリが閉鎖されている場合はどうすれば現在のアイテムを手に入れることができますか? – user7696382