mirror of
https://github.com/Finb/Bark.git
synced 2025-12-08 21:36:01 +00:00
开始兼容 communication notification, 实现自定义通知ICON
This commit is contained in:
parent
7e82fe8f7b
commit
83ab9ee53c
@ -12,6 +12,8 @@
|
||||
<array>
|
||||
<string>CloudKit</string>
|
||||
</array>
|
||||
<key>com.apple.developer.usernotifications.communication</key>
|
||||
<true/>
|
||||
<key>com.apple.security.application-groups</key>
|
||||
<array>
|
||||
<string>group.bark</string>
|
||||
|
||||
@ -104,54 +104,50 @@ class NotificationService: UNNotificationServiceExtension {
|
||||
return
|
||||
}
|
||||
|
||||
// 远程图片
|
||||
if imageUrl.hasPrefix("http")
|
||||
{
|
||||
guard let imageResource = URL(string: imageUrl) else {
|
||||
complection()
|
||||
return
|
||||
}
|
||||
func finished(imageFileUrl: String){
|
||||
let copyDestUrl = URL(fileURLWithPath: imageFileUrl).appendingPathExtension(".tmp")
|
||||
// 将图片缓存复制一份,推送使用完后会自动删除,但图片缓存需要留着以后在历史记录里查看
|
||||
try? FileManager.default.copyItem(
|
||||
at: URL(fileURLWithPath: imageFileUrl),
|
||||
to: copyDestUrl)
|
||||
|
||||
func finished(){
|
||||
let cacheFileUrl = cache.cachePath(forKey: imageResource.cacheKey)
|
||||
let copyDestUrl = URL(fileURLWithPath: cacheFileUrl).appendingPathExtension(".tmp")
|
||||
// 将图片缓存复制一份,推送使用完后会自动删除,但图片缓存需要留着以后在历史记录里查看
|
||||
try? FileManager.default.copyItem(
|
||||
at: URL(fileURLWithPath: cacheFileUrl),
|
||||
to: copyDestUrl)
|
||||
|
||||
if let attachment = try? UNNotificationAttachment(
|
||||
identifier: "image",
|
||||
url: copyDestUrl,
|
||||
options: [UNNotificationAttachmentOptionsTypeHintKey : kUTTypePNG]){
|
||||
bestAttemptContent.attachments = [ attachment ]
|
||||
}
|
||||
complection()
|
||||
if let attachment = try? UNNotificationAttachment(
|
||||
identifier: "image",
|
||||
url: copyDestUrl,
|
||||
options: [UNNotificationAttachmentOptionsTypeHintKey : kUTTypePNG]){
|
||||
bestAttemptContent.attachments = [ attachment ]
|
||||
}
|
||||
|
||||
|
||||
// 先查看图片缓存
|
||||
if cache.diskStorage.isCached(forKey: imageResource.cacheKey) {
|
||||
finished()
|
||||
return
|
||||
}
|
||||
|
||||
// 下载图片
|
||||
Kingfisher.ImageDownloader.default.downloadImage(with: imageResource, options: nil) { result in
|
||||
guard let result = try? result.get() else {
|
||||
complection()
|
||||
return
|
||||
}
|
||||
// 缓存图片
|
||||
cache.storeToDisk(result.originalData, forKey: imageResource.cacheKey, expiration: StorageExpiration.never) { r in
|
||||
finished()
|
||||
}
|
||||
}
|
||||
}
|
||||
// 本地图片
|
||||
else{
|
||||
complection()
|
||||
}
|
||||
|
||||
// 远程图片
|
||||
guard let imageResource = URL(string: imageUrl) else {
|
||||
complection()
|
||||
return
|
||||
}
|
||||
|
||||
func downloadFinished(){
|
||||
let cacheFileUrl = cache.cachePath(forKey: imageResource.cacheKey)
|
||||
finished(imageFileUrl: cacheFileUrl)
|
||||
}
|
||||
|
||||
// 先查看图片缓存
|
||||
if cache.diskStorage.isCached(forKey: imageResource.cacheKey) {
|
||||
downloadFinished()
|
||||
return
|
||||
}
|
||||
|
||||
// 下载图片
|
||||
Kingfisher.ImageDownloader.default.downloadImage(with: imageResource, options: nil) { result in
|
||||
guard let result = try? result.get() else {
|
||||
complection()
|
||||
return
|
||||
}
|
||||
// 缓存图片
|
||||
cache.storeToDisk(result.originalData, forKey: imageResource.cacheKey, expiration: StorageExpiration.never) { r in
|
||||
downloadFinished()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user