开始兼容 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,20 +104,11 @@ class NotificationService: UNNotificationServiceExtension {
return
}
//
if imageUrl.hasPrefix("http")
{
guard let imageResource = URL(string: imageUrl) else {
complection()
return
}
func finished(){
let cacheFileUrl = cache.cachePath(forKey: imageResource.cacheKey)
let copyDestUrl = URL(fileURLWithPath: cacheFileUrl).appendingPathExtension(".tmp")
func finished(imageFileUrl: String){
let copyDestUrl = URL(fileURLWithPath: imageFileUrl).appendingPathExtension(".tmp")
// 使
try? FileManager.default.copyItem(
at: URL(fileURLWithPath: cacheFileUrl),
at: URL(fileURLWithPath: imageFileUrl),
to: copyDestUrl)
if let attachment = try? UNNotificationAttachment(
@ -129,10 +120,20 @@ class NotificationService: UNNotificationServiceExtension {
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) {
finished()
downloadFinished()
return
}
@ -144,15 +145,10 @@ class NotificationService: UNNotificationServiceExtension {
}
//
cache.storeToDisk(result.originalData, forKey: imageResource.cacheKey, expiration: StorageExpiration.never) { r in
finished()
downloadFinished()
}
}
}
//
else{
complection()
}
}
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {