Compare commits

...

4 Commits

Author SHA1 Message Date
Fin
9a44d9e3a1 添加 Cloudflare Web Analytics 2025-12-02 14:15:53 +08:00
Fin
17026e40db 修复报错 2025-12-02 10:54:53 +08:00
Fin
bd1ef3439e 修复markdown不能复制推送的问题 2025-12-02 10:46:05 +08:00
Fin
537759497a 不适用 Realm 全局变量 2025-12-02 10:42:43 +08:00
4 changed files with 35 additions and 22 deletions

View File

@ -26,6 +26,7 @@ class NotificationService: UNNotificationServiceExtension {
// ciphertext
let processors: [NotificationContentProcessorItem] = [
.ciphertext,
.markdown,
.level,
.badge,
.autoCopy,
@ -33,7 +34,6 @@ class NotificationService: UNNotificationServiceExtension {
.setIcon,
.setImage,
.mute,
.markdown,
.call
]

View File

@ -10,11 +10,6 @@ import Foundation
import RealmSwift
class ArchiveProcessor: NotificationContentProcessor {
private lazy var realm: Realm? = {
Realm.Configuration.defaultConfiguration = kRealmDefaultConfiguration
return try? Realm()
}()
func process(identifier: String, content bestAttemptContent: UNMutableNotificationContent) async throws -> UNMutableNotificationContent {
let userInfo = bestAttemptContent.userInfo
@ -34,23 +29,28 @@ class ArchiveProcessor: NotificationContentProcessor {
let id = userInfo["id"] as? String
let markdown = userInfo["markdown"] as? String
try? realm?.write {
let message = Message()
if let id, !id.isEmpty {
message.id = id
if let realm = {
Realm.Configuration.defaultConfiguration = kRealmDefaultConfiguration
return try? Realm()
}() {
try? realm.write {
let message = Message()
if let id, !id.isEmpty {
message.id = id
}
message.title = title
message.subtitle = subtitle
message.body = body
if let markdown, !markdown.isEmpty {
message.body = markdown
message.bodyType = Message.BodyType.markdown.rawValue
}
message.url = url
message.image = image
message.group = group
message.createDate = Date()
realm.add(message, update: .all)
}
message.title = title
message.subtitle = subtitle
message.body = body
if let markdown, !markdown.isEmpty {
message.body = markdown
message.bodyType = Message.BodyType.markdown.rawValue
}
message.url = url
message.image = image
message.group = group
message.createDate = Date()
realm?.add(message, update: .all)
}
}
return bestAttemptContent

View File

@ -29,6 +29,14 @@ class MarkdownProcessor: NotificationContentProcessor {
// body \n\n
.replacingOccurrences(of: "\n\n+", with: "\n", options: .regularExpression)
bestAttemptContent.body = body
/// APS , Porgressor 使
var aps = userInfo["aps"] as? [String: Any] ?? [:]
var alert = aps["alert"] as? [String: Any] ?? [:]
alert["body"] = body
aps["alert"] = alert
bestAttemptContent.userInfo["aps"] = aps
return bestAttemptContent
}
}

View File

@ -31,4 +31,9 @@
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-bash.min.js"></script>
</body>
<!-- Cloudflare Web Analytics -->
<script defer src='https://static.cloudflareinsights.com/beacon.min.js'
data-cf-beacon='{"token": "6ad048c5cd404e309d826a089e2826f1"}'></script>
<!-- End Cloudflare Web Analytics -->
</html>