AVAssetWriter 元数据日期问题

AVAssetWriter metadata Date issue

我有以下代码在 AVAssetWriter 中写入日期元数据,这在 iOS13 中出错了。需要知道这是 iOS13 错误还是我做错了什么.

     private var metadataItems:[AVMetadataItem]? {

       get {
        let locale = Locale.current
        var metadata:[AVMetadataItem] = []
        let date = Date()
        let calendar = Calendar.current

        let year = calendar.component(.year, from: date)
        let month = calendar.component(.month, from: date)
        let day = calendar.component(.day, from: date)
        let hour = calendar.component(.hour, from: date)
        let minute = calendar.component(.minute, from: date)
        let second = calendar.component(.second, from: date)
        let timezone = TimeZone.current
        let timezoneStr = timezone.abbreviation()

        let creationDateMetaData = AVMutableMetadataItem()
        creationDateMetaData.keySpace = AVMetadataKeySpace.common
        creationDateMetaData.key = AVMetadataKey.commonKeyCreationDate as NSCopying & NSObjectProtocol
        creationDateMetaData.locale = locale
        creationDateMetaData.value = String(format:"%04ld-%02ld-%02ld %02ld:%02ld:%02ld %@",year, month, day, hour, minute, second, timezoneStr!) as NSCopying & NSObjectProtocol   

         metadata.append(creationDateMetaData)

         return metadata
       }

当使用 PHPhotoLibrary 导出到照片库时,它在照片库中显示 1970 年 1 月 1 日或有时 469231 年 9 月 2 日作为创建日期。我做错了什么?

我还尝试了以下方法:

 extension Date {

    static let dateFormatter: DateFormatter = iso8601DateFormatter()

    fileprivate static func iso8601DateFormatter() -> DateFormatter {
        let formatter = DateFormatter()
        formatter.calendar = Calendar(identifier: .iso8601)
        formatter.timeZone = TimeZone(secondsFromGMT: 0)
        formatter.locale = Locale(identifier: "en_US_POSIX")
        formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
        return formatter
     }

  // http://nshipster.com/nsformatter/
  // http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
     public func iso8601() -> String {
        return Date.iso8601DateFormatter().string(from: self)
     }

 }            

然后简单地使用:

        let creationDateMetaData = AVMutableMetadataItem()
        creationDateMetaData.keySpace = AVMetadataKeySpace.common
        creationDateMetaData.key = AVMetadataKey.commonKeyCreationDate as NSCopying & NSObjectProtocol
        creationDateMetaData.value = Date().iso8601() as NSCopying & NSObjectProtocol

但是没有效果!

改变

    let creationDateMetaData = AVMutableMetadataItem()
    creationDateMetaData.keySpace = AVMetadataKeySpace.common
    creationDateMetaData.key = AVMetadataKey.commonKeyCreationDate as NSCopying & NSObjectProtocol
    creationDateMetaData.value = Date().iso8601() as NSCopying & NSObjectProtocol

    let creationDateMetaData = AVMutableMetadataItem()
    creationDateMetaData.keySpace = .common
    creationDateMetaData.key = AVMetadataKey.commonKeyCreationDate as NSString
    creationDateMetaData.value = Date() as NSDate