Update #2: ELCImagePickerController

    October 18th, 2011 Posted by: - posted under:Articles » Featured

    Welcome back to another update to the . If you’re not familiar with this class I’d suggest you check out the following posts:

    Cloning UIImagePickerController using the Assets Library Framework
    Update: ELCImagePickerController

    A lot has happened in the iOS world since the creation of this code. With the advent of every new version of iOS there are always exciting new features and bug fixes. Sometimes subtle code changes sneak into classes we’ve been using for a while though. These changes might create bugs that can be hard to find. Whenever I am debugging code on a new release, especially if it’s a beta release, I try to remember to consult the docs sooner than later. When we started to get reports of ELCImagePickerController not working in iOS 5, it was time to do some homework.

    The problem seemed to be that the albums were coming up as empty, even when people had plenty of pictures to display. Someone in the community found a quick work around that if you don’t release the library object, then the code starts working again! Leaking memory like this is never the right answer, but it was a great starting spot to figure out the real problem.

    The problem seemed to be arising here:

    Commenting out the release fixed the problem? Very odd. I floundered around the code a bit before remembering to go to the documentation for this new (beta, at the time) version of iOS. Lo and behold!

    The last sentence is key, “The lifetimes of objects you get back from a library instance are tied to the life of the library instance.” If we release our library instance right there we aren’t going to have access to any of the objects we get back from it anymore! This is new behavior in iOS 5. To adapt to it I just moved the library variable out to be an instance variable of the class and didn’t release it until dealloc is called.

    Not such a hard fix once I knew what to look for, just have to remember that the documentation is there for a reason! Thanks to the community for the feedback that made tracking down this bug much easier.

    We’re back in action!

    As I was troubleshooting this control I kept running into the problem that my simulator didn’t have any pictures in it. If only there was a utility to populate the photo album for me. Maybe it could grab images of cute little kittens from the internet or something? Hmm. Stay tuned to iCodeBlog for more on this!