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

Asynchronous issue. #3

Open
phongleq opened this issue Jan 21, 2016 · 11 comments
Open

Asynchronous issue. #3

phongleq opened this issue Jan 21, 2016 · 11 comments
Labels

Comments

@phongleq
Copy link

There seem to be issues when trying to load gifs asynchronously. Most of the time it crashes because of nil values. It also seems to be the case when you swap out a gif for another one.

@khaledmtaha
Copy link
Owner

You're absolutely right. I've already fixed this issue on a build that I currently have. I'll be pushing it out soon. I'll update you once that happens.

Thanks for the feedback and your help.

@johnrickman
Copy link

Bump

@johnrickman
Copy link

Any status update on this?

@mpc20001
Copy link

mpc20001 commented Mar 4, 2016

any update on this?

2 similar comments
@MMasterson
Copy link

any update on this?

@chx632996066
Copy link

any update on this?

@khaledmtaha
Copy link
Owner

Sorry, I'm currently snowed under at work. I'll update it this Sunday.

On Mon, Mar 21, 2016 at 4:13 AM, hongxi notifications@github.com wrote:

any update on this?


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#3 (comment)

Khaled M. Taha

Kindly note that this is my personal email address, and it would be greatly
appreciated if this address remains free of any unauthorized mailing lists
and/or forwards.

@johnrickman
Copy link

Thanks a lot, waiting for this so we can start adding cat gifs!!

@khaledmtaha
Copy link
Owner

Haha, this is top priority folks!

Jokes aside, I apologize for making y'all wait. Just a little longer.

On Mon, Mar 21, 2016 at 1:24 PM, John Rickman notifications@github.com
wrote:

Thanks a lot, waiting for this so we can start adding cat gifs!!


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#3 (comment)

Khaled M. Taha

Kindly note that this is my personal email address, and it would be greatly
appreciated if this address remains free of any unauthorized mailing lists
and/or forwards.

@khaledmtaha
Copy link
Owner

Currently working on it, this has already been resolved as part of FLAnimatedImage. I'm adding this function:

func loadAnimatedImageWithURL(url:NSURL, completion:(animatedImage:XAnimatedImage)-> ()) {

    // Create a file to store the GIF and its corresponding data

    let fileName = url.lastPathComponent!
    let diskPath = (NSHomeDirectory() as NSString).stringByAppendingPathComponent(fileName)
    var animatedImageData = NSFileManager.defaultManager().contentsAtPath(diskPath)

    var animatedImage = XAnimatedImage()

    if animatedImageData?.bytes == nil {
        // Newly created, then download
        NSURLSession.sharedSession().dataTaskWithURL(url) { (data:NSData?, response:NSURLResponse?, error:NSError?) -> Void in
            if error == nil {
                animatedImageData = data
                animatedImage = XAnimatedImage(initWithAnimatedGIFData: animatedImageData!)
                if let _ = animatedImage.posterImage {
                    dispatch_async(dispatch_get_main_queue(), { () -> Void in
                        completion(animatedImage: animatedImage)
                    })       
                    data?.writeToFile(diskPath, atomically: true)
                }
            } else {
                print("error exists")
            }
            } .resume()
    } else {
        animatedImage = XAnimatedImage(initWithAnimatedGIFData: animatedImageData!)
            completion(animatedImage: animatedImage)   
    }
    }`

Currently called within the func viewDidLoad() as such:

    let urlString = "https://i.imgur.com/8W2mtHB.gif"
    let url = NSURL(string: urlString)
    self.loadAnimatedImageWithURL(url!) { (animatedImage) -> () in
        self.animatedImageA = animatedImage
        self.animatedImageViewA.animatedImage = self.animatedImageA
        self.animatedImageA.debug_delegate = self.debugViewA
        self.animatedImageViewA.debug_delegate = self.debugViewA
        self.debugViewA.image = self.animatedImageA            
    }

It seems to work. But I'm still testing. Thought to give y'all an update.

khaledmtaha added a commit that referenced this issue Apr 14, 2016
…ithURL' that downloads the gif file, and then proceeds to display it
@khaledmtaha
Copy link
Owner

Let me know if this fixes the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants