开始兼容 communication notification, 实现自定义通知ICON

This commit is contained in:
Fin 2021-09-24 15:01:59 +08:00
parent 7e82fe8f7b
commit 83ab9ee53c
2 changed files with 42 additions and 44 deletions

View File

@ -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>

View File

@ -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) {