Skip to content

Commit

Permalink
下拉推送可以复制全部内容
Browse files Browse the repository at this point in the history
  • Loading branch information
Finb committed Jan 6, 2025
1 parent a57fdaa commit 15f0894
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Bark/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
func presentController() {
let alert = (userInfo["aps"] as? [String: Any])?["alert"] as? [String: Any]
let title = alert?["title"] as? String
let subtitle = alert?["subtitle"] as? String
let body = alert?["body"] as? String
let url: URL? = {
if let url = userInfo["url"] as? String {
Expand Down Expand Up @@ -182,11 +183,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
if let title = title {
shareContent += "\(title)\n"
}
if let subtitle = subtitle {
shareContent += "\(subtitle)\n"
}
if let body = body {
shareContent += "\(body)\n"
}
for (key, value) in userInfo {
if ["aps", "title", "body", "url"].contains((key as? String) ?? "") {
if ["aps", "title", "subtitle", "body", "url"].contains((key as? String) ?? "") {
continue
}
shareContent += "\(key): \(value) \n"
Expand Down
16 changes: 15 additions & 1 deletion notificationContentExtension/NotificationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,21 @@ class NotificationViewController: UIViewController, UNNotificationContentExtensi
if let copy = userInfo["copy"] as? String {
UIPasteboard.general.string = copy
} else {
UIPasteboard.general.string = response.notification.request.content.body
var content = ""
if !response.notification.request.content.title.isEmpty {
content += "\(response.notification.request.content.title)\n"
}
if !response.notification.request.content.subtitle.isEmpty {
content += "\(response.notification.request.content.subtitle)\n"
}
if !response.notification.request.content.body.isEmpty {
content += "\(response.notification.request.content.body)\n"
}
if let url = userInfo["url"] as? String, !url.isEmpty {
content += "\(url)\n"
}
content = content.trimmingCharacters(in: .whitespacesAndNewlines)
UIPasteboard.general.string = content
}

showTips(text: NSLocalizedString("Copy", comment: ""))
Expand Down

0 comments on commit 15f0894

Please sign in to comment.