美文网首页
Notification Service download vi

Notification Service download vi

作者: 私人云笔记_骁勇波波 | 来源:发表于2020-11-27 16:10 被阅读0次

private func loadMediaDataAndCreateNotificationAttachment(with url:URL, defautType:String, completion:@escaping((UNNotificationAttachment?) ->Void)) {

    letsession =URLSession(configuration: .default)

    letdownloadTask = session.downloadTask(with: url) { [weakself] (url, response, error)in

        guard let self = self else { return }

        ifleturl = url {

            lettypeString =self.determineType(fileType: response?.mimeType??"") ?? defautType

            letpathUrl =self.getSavePathUrl(typeString: typeString)

            do{

                tryFileManager.default.moveItem(at: url, to: pathUrl)

                letattachment =tryUNNotificationAttachment(identifier: typeString, url: pathUrl, options:nil)

                completion(attachment)

            }catch{

                print("Error create attachment:\(error.localizedDescription)")

                completion(nil)

            }

        }elseifleterror = error {

            print("Error downloading attachment:\(error.localizedDescription)")

            completion(nil)

        }

    }

    downloadTask.resume()

}

相关文章

网友评论

      本文标题:Notification Service download vi

      本文链接:https://www.haomeiwen.com/subject/rkcgahtx.html