Comments (11)
Hi @zenangst!
I did a quick debug and I found that in ImagePicker/ImageGalleryView.swift in collectionView:didSelectItemAtIndexPath the block is called more than one time if I select an iCloud image and that results on a selection and a quick deselection of the image.
from imagepicker.
Hey @diegof29, thanks for bringing this to our attentions, we will do some digging to see what we come up with.
What happens when try to select something from iCloud? Do you get any warnings or errors in the logs?
from imagepicker.
@diegof29 still haven't had the time to look into this properly I'm afraid. If you do solve it before we do, feel free to make a pull request.
from imagepicker.
+1 for support
from imagepicker.
app crash if I pick a picture from iCloud. Does this library have support for getting iCloud pictures?
from imagepicker.
+1
from imagepicker.
@aitornillooo @weakfl Hi, what crash log is it?
from imagepicker.
@onmyway133 Sorry if my answer was misleading. The app doesn't crash, but images get immediately deselected as @diegof29 has described.
from imagepicker.
I did a little debugging and it turns out the AssetManager
indeed calls the completion block in resolveAsset()
multiple times.
The reason is the default PHImageRequestOptionsDeliveryMode.opportunistic
:
If the isSynchronous property is false, Photos may call the resultHandler block (that you specified in the requestImage(for:targetSize:contentMode:options:resultHandler:) method more than once.
It turns out that the completion block is executed 3 times if the image is on the device, so the image ends up selected by favourable circumstances ;)
I guess the completion block is executed twice if the image is in the cloud, which results in immediate deselection of the image.
What's the reason you're resolving assets on didSelectItemAtIndexPath
in ImageGalleryView
anyway?
Unfortunately I couldn't really test with iCloud images because for some reason they're not included in the gallery view on iOS 10. I don't know if PHAsset.fetchAssetsWithMediaType()
doesn't return iCloud images on iOS 10 or if it's just because I have just set up my iPhone 7. I'll have to do some more digging...
EDIT:
It turned out that iCloud images are still included, but the order is reversed. Looks like the order gets messed up when restoring from an iCloud backup.
I would suggest to add an NSSortDescriptor
to the fetch()
function in AssetManager
and order by creation date:
public static func fetch(completion: (assets: [PHAsset]) -> Void) {
let fetchOptions = PHFetchOptions()
fetchOptions.sortDescriptors = [NSSortDescriptor(key:"creationDate", ascending: true)]
let authorizationStatus = PHPhotoLibrary.authorizationStatus()
var fetchResult: PHFetchResult?
guard authorizationStatus == .Authorized else { return }
if fetchResult == nil {
fetchResult = PHAsset.fetchAssetsWithMediaType(.Image, options: fetchOptions)
}
if fetchResult?.count > 0 {
var assets = [PHAsset]()
fetchResult?.enumerateObjectsUsingBlock { object, index, stop in
if let asset = object as? PHAsset {
assets.insert(asset, atIndex: 0)
}
}
dispatch_async(dispatch_get_main_queue(), {
completion(assets: assets)
})
}
}
I've also removed the resolveAsset()
call in didSelectItemAtIndexPath
in ImageGalleryView
to avoid multiple calls of the completion block:
public func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
guard let cell = collectionView.cellForItemAtIndexPath(indexPath)
as? ImageGalleryViewCell else { return }
let asset = assets[indexPath.row]
if cell.selectedImageView.image != nil {
UIView.animateWithDuration(0.2, animations: {
cell.selectedImageView.transform = CGAffineTransformMakeScale(0.1, 0.1)
}) { _ in
cell.selectedImageView.image = nil
}
self.selectedStack.dropAsset(asset)
} else if self.imageLimit == 0 || self.imageLimit > self.selectedStack.assets.count {
cell.selectedImageView.image = AssetManager.getImage("selectedImageGallery")
cell.selectedImageView.transform = CGAffineTransformMakeScale(0, 0)
UIView.animateWithDuration(0.2) { _ in
cell.selectedImageView.transform = CGAffineTransformIdentity
}
self.selectedStack.pushAsset(asset)
}
}
Images from the iCloud photo library do work with these changes, but imho this is only a partial solution.
It might take some time to load images from the cloud when resolving assets on doneButtonDidPress()
, so some kind of progress/activity indicator might be a good idea.
from imagepicker.
@zenangst @onmyway133 Take a look at my previous comment for a partial solution.
from imagepicker.
@weakfl Hi, sorry for late reply
About deliveryMode
, it is solved in #207
About iCloud photos in gallery view, it is strange that it appear there, but anyway, I think this #262 can solve it
Feel free to make any PR to improve this 🚀
from imagepicker.
Related Issues (20)
- [BUG]the backgroud music is stoped HOT 1
- Unselecting image returns nil array HOT 2
- AVCaptureDevice device Type HOT 3
- on iOS 14 capture put images to camera roll but shutter counter and picture preview are not updated HOT 1
- Cannot unselecting image when setting "imageLimit" to 1. HOT 4
- If shot button pressed too frequently image might loss on old iPhones HOT 1
- AVCaptureStillImageOutput' was deprecated in iOS 10.0: Use AVCapturePhotoOutput instead HOT 1
- 'flashMode' and 'isflashMode' was deprecated in iOS 10.0: Use AVCapturePhotoSettings.flashMode instead. HOT 1
- Gallery In Full Screen Mode HOT 2
- SPM support HOT 8
- When I select photos, I have no way of knowing which photos I chose.
- Camera does not rotate HOT 1
- The ultra wide angle does not work with the camera HOT 1
- Doesn't compile in XCode 13 HOT 9
- Is there a camera only mode? HOT 1
- using callback instead of delegate
- Is this project officialy "stopped" ?
- doneButtonDidPress not working
- Ultra Wide Angle Functionality Support HOT 1
- Multiple image Select but Not getting While using delegate also
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from imagepicker.