-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
PHAsset+Metadata.swift
40 lines (36 loc) · 1.25 KB
/
PHAsset+Metadata.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import Foundation
import Photos
import MobileCoreServices
import AVFoundation
extension PHAsset {
public var uniformTypeIdentifier: String? {
let resources = PHAssetResource.assetResources(for: self)
var types: [PHAssetResourceType.RawValue] = []
if mediaType == PHAssetMediaType.image {
types = [PHAssetResourceType.photo.rawValue]
} else if mediaType == PHAssetMediaType.video {
types = [PHAssetResourceType.video.rawValue]
}
for resource in resources {
if types.contains(resource.type.rawValue) {
return resource.uniformTypeIdentifier
}
}
return nil
}
public var originalFilename: String? {
let resources = PHAssetResource.assetResources(for: self)
var types: [PHAssetResourceType.RawValue] = []
if mediaType == PHAssetMediaType.image {
types = [PHAssetResourceType.photo.rawValue]
} else if mediaType == PHAssetMediaType.video {
types = [PHAssetResourceType.video.rawValue]
}
for resource in resources {
if types.contains(resource.type.rawValue) {
return resource.originalFilename
}
}
return nil
}
}