2016-04-28 5 views
0

私は、iOSプロジェクト用にSwiftyDropboxライブラリを使用しています。フォルダのリストを再帰的に取得し、ファイルが写真かビデオかを確認しています。Dropbox 2.0 Swift API:メディアメタデータを取得する方法

 client.files.getMetadata(path: fileURL, includeMediaInfo: true).response { response, error in 

     if let file = response as? Files.FileMetadata { 
      if file.mediaInfo != nil { 

      // ??? how to get file.mediaInfo.metadata 
      // specifically, I need the mediaMetadata 

      } 
     } 
     } 

私はfile.mediaInfo(それが存在する場合、メタデータが存在することを意味するが、ドキュメントは、実際のメタデータ自体を取得する方法を示していない、ビデオのための写真や期間について(具体的には、寸法)を見ることができます。

私はfile.mediaInfoの記述からこれを取得(そしてそこから返された文字列を解析し)、それはハックと将来セーフではありませんすることができます。このデータを取得するための別の方法はありますか?

これはデータを取得したいクラスです(Files.swift内):

public class MediaMetadata: CustomStringConvertible { 
    /// Dimension of the photo/video. 
    public let dimensions : Files.Dimensions? 
    /// The GPS coordinate of the photo/video. 
    public let location : Files.GpsCoordinates? 
    /// The timestamp when the photo/video is taken. 
    public let timeTaken : NSDate? 
    public init(dimensions: Files.Dimensions? = nil, location: Files.GpsCoordinates? = nil, timeTaken: NSDate? = nil) { 
     self.dimensions = dimensions 
     self.location = location 
     self.timeTaken = timeTaken 
    } 
    public var description : String { 
     return "\(prepareJSONForSerialization(MediaMetadataSerializer().serialize(self)))" 
    } 
} 

答えて

3

ここではサンプルです:

Dropbox.authorizedClient!.files.getMetadata(path: "/test.jpg", includeMediaInfo: true).response { response, error in 
    if let result = response as? Files.FileMetadata { 
     print(result.name) 

     if result.mediaInfo != nil { 
      switch result.mediaInfo! as Files.MediaInfo { 
      case .Pending: 
       print("Media info is pending...") 
      case .Metadata(let mediaMetadata): 
       print(mediaMetadata.dimensions) 
       print(mediaMetadata.location) 
       print(mediaMetadata.timeTaken) 
      } 
     } 
    } else { 
     print(error!) 
    } 
} 
関連する問題