Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image always nil on real device #39

Closed
rico237 opened this issue Nov 10, 2017 · 2 comments
Closed

Image always nil on real device #39

rico237 opened this issue Nov 10, 2017 · 2 comments

Comments

@rico237
Copy link

rico237 commented Nov 10, 2017

When using pod on simulator, code work like charm but when using on real device fullResolutionImage is always nil.
I've been working on this for 3 hours ... and i'm going nowhere do you have a solution for this ?

PS: I'm using iPhone 7+ with iOS 11.1

func dismissPhotoPicker(withTLPHAssets: [TLPHAsset]) {
        if withTLPHAssets.count != 0 {
            let asset = withTLPHAssets[0]

            if asset.type == .photo || asset.type == .livePhoto {
                self.photoArray[self.selectedRow] = asset.fullResolutionImage
            }

            self.refreshUI()
        }
    }
@tilltue
Copy link
Owner

tilltue commented Nov 10, 2017

@rico237
Are you used icloud photos?
I thinks, "fullResolutionImage" method is get image request using wrong options.

https://stackoverflow.com/questions/31037859/phimagemanager-requestimageforasset-returns-nil-sometimes-for-icloud-photos

Try this.

func dismissPhotoPicker(withTLPHAssets: [TLPHAsset]) {
        // use selected order, fullresolution image
        if withTLPHAssets.count != 0 {
            let asset = withTLPHAssets[0]
            self.getImage(phasset: asset.phAsset)
            print("aa\(test)")
        }
    }
func getImage(phasset: PHAsset?) {
        guard let asset = phasset else { return }
        let options = PHImageRequestOptions()
        options.isSynchronous = false
        options.isNetworkAccessAllowed = true
        options.deliveryMode = .opportunistic
        options.version = .current
        options.resizeMode = .exact
        options.progressHandler = { (progress,error,stop,info) in
            //progressBlock(progress)
        }
        let requestId = PHCachingImageManager().requestImageData(for: asset, options: options) { (imageData, dataUTI, orientation, info) in
            if let data = imageData,let _ = info {
                //completionBlock(UIImage(data: data))
                print(data)
            }
        }
    }

@rico237
Copy link
Author

rico237 commented Nov 12, 2017

OMG !!
I really thank you for your answer and how quickly you provided me with a solution <3
It worked like a charm
Again thank you so much !! 👍

@tilltue tilltue closed this as completed Nov 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants