In Android we get camera images only i.e. when we open gallery programmatically, but in iOS when we open Photos, we get camera roll images and other unwanted images along with it like whatsapp images. How to filter for only camera images when opening gallery?
What I have tried in Swift 4 is shown below:
func getPhotosAndVideos()
{
let fetchOptions = PHFetchOptions()
fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate",ascending: false)]
fetchOptions.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.image.rawValue)
print("fetchOptions : ", fetchOptions)
let assets = PHAsset.fetchAssets(with: fetchOptions)
var results = NSMutableArray()
assets.enumerateObjects { (obj, idx, bool) -> Void in
results.add(obj)
}
let cameraRollAssets = results.filtered(using: NSPredicate(format: "sourceType == %@", argumentArray: [3]))
results = NSMutableArray(array: cameraRollAssets)
print("cameraRollAssets : ", cameraRollAssets)
print("results : ", results)
}
I want just camera images taken by my phone.