0

我有一个简单的应用程序,可以UNNotification定期发送用户。我想将一些字符串插入/粘贴到通知后面的应用程序中。

例如,如果用户在他的 iPhone 上使用Note 应用程序,当他收到我的通知时,我想在打开的 Note 中插入一些文本。

这可能吗?

这是我发送通知的代码:

    let notification = UNMutableNotificationContent()
    notification.sound = UNNotificationSound.default()
    notification.subtitle = Message
    notification.body = "Expand this notification for more options"
    notification.categoryIdentifier = "Event"
    let category = UNNotificationCategory(identifier: "Event",
                                          actions: [],
                                          intentIdentifiers: [],
                                          options: [])
    let notificationTrigger = UNCalendarNotificationTrigger(dateMatching: GenerateFireDate(), repeats: false)
    let request = UNNotificationRequest(identifier: "Event",
                                        content: notification,
                                        trigger: notificationTrigger)
    UNUserNotificationCenter.current().setNotificationCategories([category])
    UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)

更新

我知道我有一个简单的解决方案,即CopyUIPasteboard. 但我正在寻找一种替代方式,它比开放复制解决方案更方便。

4

1 回答 1

1

这是不可能的。考虑一下任何应用程序都可以在任何地方粘贴文本的情况——这不会带来很好的体验。

一种解决方法是您指示用户点击通知以打开您的应用程序。然后您可以将文本添加到剪贴板。UIPasteboard 在其文档中了解更多信息。

于 2018-01-29T07:43:55.117 回答