Featured Posts

How to background load and cache UIImageViews images It's often the case that the apps I am working on are required to download quite a couple, or even a few dozen, images and display them in a UIImageView. In looking online I found a few different methods...

Readmore

It sure does snow in Kansas! This week I am visiting my Grandmother in Kansas. Monday night I arrived at the farm just as the first snow was falling, and by Tuesday morning I couldn't have left if I wanted to. Here are some pictures...

Readmore

*Warning* Do not install software included in Panasonic... Background A while back I purchased a Panasonic camera that can not only take pictures, but also record video. I chose the camera because of this combination, in combination with it's optical zoom. Now,...

Readmore

UPS continues tradition of poor service Warning, rant ahead! I don't like posting such, but UPS is making my life miserable often enough that I feel I have to. Anyway, I purchased a product recently which the company shipped via UPS with...

Readmore

Suggestions to correct iTunes / iPhone music sync Recently I had a coworker who upgraded his iPhone to 3.0 find that he could no longer sync that iPhone with his iTunes music library on a Windows computer. It would, however, sync just fine on a Mac OS...

Readmore

  • Prev
  • Next

How to background load and cache UIImageViews images

Posted on : 18-12-2009 | By : Lane Roathe | In : Development, featured, iPhone

Tags: , , , , , ,

0

It’s often the case that the apps I am working on are required to download quite a couple, or even a few dozen, images and display them in a UIImageView. In looking online I found a few different methods of loading image data for a UIImageView in the background, and a few examples of caching image data, but they were all overly complicated for my needs, and none that combined the two ideas.

So, I’m posting here my very simply extension of the UIImageView class that provides a way to load an image in the background. It also provides an extremely simply caching system, which works great if you are displaying a list of thumbnails but would need better memory management for a true cache.

You can download the UIImageView+Cached - Simple extension to a UIImageView that allows loading of UIImageView's from URL's in the background, and also provides a very simple memory caching system. here.

The header file is pretty straight forward, it simply defines our additional methods for the UIImageView class.

// UIImageView+Cached.h
//
// Created by Lane Roathe
// Copyright 2009 Ideas From the Deep, llc. All rights reserved.

@interface UIImageView (Cached)

-(void)loadFromURL:(NSURL*)url;
-(void)loadFromURL:(NSURL*)url afterDelay:(float)delay;

@end

Note that both methods assume you already have a UIImageView to work with. While it would be fairly easy to add a method to create a UIImageView as part of the load, I chose not to because all of the places where I wanted to use this were defined in Interface Builder (IB) and hooked up to an instance variable. I do as little interface design in code as possible, even laying out all of my table cells in IB. For me it makes development a lot faster, and interface tweeks and updates not just simpler, but requiring fewer iterations.

loadFromURL: simply takes a URL to any supported image file and sets up for loading the image in the background. When the image finishes loading the UIImageView’s setImage: method will be called to update the view’s image.

loadFromURL:afterDelay: simply delays calling loadFromURL: for the amount of time (in seconds) given as the delay. I’ve used this in programs where I wanted to optimize other parts of the program to display first, but still put the image load call in the same code section (ie, typically in viewWillDisplay in my apps).
Now for the actual code, which is quite small for both a background loader and caching system.

// UIImageView+Cached.h
//
// Created by Lane Roathe
// Copyright 2009 Ideas From the Deep, llc. All rights reserved.

#import “UIImageView+Cached.h”

#pragma mark -
#pragma mark — Threaded & Cached image loading —

@implementation UIImageView (Cached)

Note here that I have hard-coded my cache for a maximum of 50 images. Typically cache systems are limited in the amount of RAM used instead of a count, but for this quick category it fit my needs. Again, if you are loading small images (like icons or thumbnails) then this will probably work fine for you as well, otherwise you probably want to Google for a real caching solution :)

#define MAX_CACHED_IMAGES 50 // max # of images we will cache before flushing cache and starting over

I used a static variable in the cache getter to simplify the code. I don’t really like this, but it does mean that I don’t have to worry about calling an init or doing any heavier extension of UIImageView so all in all while it’s not the best solution, it does what it needs quite well.

The method simply checks to see if we have already allocated a dictionary we can use to cache our image references, and if not allocate said dictionary. The method returns the dictionary reference.

// method to return a static cache reference (ie, no need for an init method)
-(NSMutableDictionary*)cache
{

static NSMutableDictionary* _cache = nil;

if( !_cache )

_cache = [NSMutableDictionary dictionaryWithCapacity:MAX_CACHED_IMAGES];

assert(_cache);
return _cache;

}

This is the meet and potatoes of the code here. The first thing it does is look to see if the requested image is in our cache. Note that it does this by the URL ’string’ returned by the NSObject description method. This is about as simple a check as you can do, because it does not handle any cases where the image changes on the server, there are two identical images with different URL’s, two URL’s resolve to the same image (https and http for instance), etc.

If we don’t find the image in the cache, we setup an allocation pool because we are going to assume that we are not on the main thread, which is true if either of the public methods for this extension are called. We then use the standard NSData method to load the file from the URL and pass that to UIImage to translate that data into something the system can use (ie, the UIImage). After we load a new image, we first check to see if we have available room in our cache, and if not clear the cache out (again, very simple caching here!). Then in either case we can add the image to the cache.

Finally the method calls the UIImageView’s setImage: method to update the view with the new image data. We don’t call it directly because again we are assuming that one of the public API’s were called, in which case we would not be on the main thread, and making any UI calls is therefore bad. Thus, we use the performSelectorOnMainThread: method to call setImage: so that it can be done safely.

// Loads an image from a URL, caching it for later loads
// This can be called directly, or via one of the threaded accessors
-(void)cacheFromURL:(NSURL*)url
{

UIImage* newImage = [[self cache] objectForKey:url.description];
if( !newImage )
{

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSError *err = nil;
newImage = [[UIImage imageWithData: [NSData dataWithContentsOfURL:url options:0 error:&err]] retain];
if( newImage )
{

// check to see if we should flush existing cached items before adding this new item
if( [[self cache] count] >= MAX_CACHED_IMAGES )

[[self cache] removeAllObjects];

[[self cache] setValue:newImage forKey:url.description];

}
else

NSLog( @"UIImageView:LoadImage Failed: %@", err );

[pool drain];

}

if( newImage )

[self performSelectorOnMainThread:@selector(setImage:) withObject:newImage waitUntilDone:NO];

}

And finally, the public methods. Each is very simple; loadFromURL: uses performSelectorInBackground: to call the cacheFromURL: method above on a different thread. This allows the main thread (which is running the UI and main loop of your app) to continue on uninterrupted. This slows down the loading a bit, but keeps the user interactions and interface updates nice and smooth, resulting in a better end user experience.

The loadFromURL:afterDelay: method simply uses the afterDelay version of performSelector: to call loadFromURL: after the specified delay. The only purpose here is to provide a way to organize downloads in a very simple, yet usable fashion.

For instance, let’s say I am going to present a list of home for sale, which requires downloading 20 images, and at the same time make 20 web page requests for descriptions of the homes, their prices, etc. We could wait for everything to load, but that is not good end user design (imo). Instead, I can request the UIImageView’s for those 20 homes update their images, but delay that load for 2-3 seconds. Then, I can grab the text data from the website (which typically comes down very fast), and present the view to the user. Thus the user can start reading about the properties and as images come in the view will automatically update the images the user sees.

// Methods to load and cache an image from a URL on a separate thread
-(void)loadFromURL:(NSURL *)url
{

[self performSelectorInBackground:@selector(cacheFromURL:) withObject:url];

}

-(void)loadFromURL:(NSURL*)url afterDelay:(float)delay
{

[self performSelector:@selector(loadFromURL:) withObject:url afterDelay:delay];

}
@end

OK, that’s it. In case you missed it above, you can download the UIImageView+Cached - Simple extension to a UIImageView that allows loading of UIImageView's from URL's in the background, and also provides a very simple memory caching system. here.

Hopefully this will prove helpful to someone :)
Update: Take a look at Michael Amorose’s additions to UIImageView’s if mine isn’t your cup of tea.

It sure does snow in Kansas!

Posted on : 12-12-2009 | By : Lane Roathe | In : Family, featured

Tags: , ,

2

This week I am visiting my Grandmother in Kansas. Monday night I arrived at the farm just as the first snow was falling, and by Tuesday morning I couldn’t have left if I wanted to. Here are some pictures of what things looked like the first couple of days I was here!

Snow Barn

Snow Barn

Kitty tracks on the snow

Kitty tracks on the snow

Back porch before the blizzard

Back porch before the blizzard

Back porch after blizzard. Taken through screen because all of the windows were completely covered with either snow or frost!

Back porch after blizzard. Taken through screen because all of the windows were completely covered with either snow or frost!

Here is the Facebook photo album if interested.

It took a front loader to clear the driveway so I would be able to get out if I needed, although as of Friday night I had not even attempted it since we have plenty to eat in the house, and the electricity, heat and internet are all working. Grandma’s cat is not at all happy having to wade through snow to go to the bathroom! (Plus, I imagine it’s rather difficult to find any ground that isn’t frozen … probably has to go all the way to the barn, which in good weather is nothing but in snow deeper than the cat is high I noticed he didn’t even try (well, at least I didn’t see any cat tracks going out that way).

*Warning* Do not install software included in Panasonic products!

Posted on : 02-11-2009 | By : Lane Roathe | In : Rant, featured

Tags: , , , , , , , , ,

0

Background
A while back I purchased a Panasonic camera that can not only take pictures, but also record video. I chose the camera because of this combination, in combination with it’s optical zoom. Now, the camera works great and importing photos into iPhoto has always been a snap.

Unfortunately, only recently did I first try recording a movie and importing it. I say unfortunately because while the video recorded fine, when it came to importing I found that not only am I not able to import video despite the Panasonic advertising this capability for Mac OS X, but also the software included on Panasonic CD’s installs extremely invasive “pop-up” programs that behave just like trojan/virus software!

I really wish I had tried the video capabilities before the store’s return policy expired, as I would have immediately returned the damn thing.

The gory path to finding out I’ve been taken
After recording my first movie on the camera I attempted to import the movie into iMovie. Unlike all other cameras I’ve had (including several Nokia phones) iMovie would not import the movies when I connected the camera. In fact, it said there was no media available for import. Huh? iPhoto handles the pictures fine, what’s up with the movies?

OK, so maybe Panasonic is using a proprietary format I thought. Not what I was expecting, but if so there should be software on the CD that came with the camera that would allow me to import my movies. After searching for a few days (off and on of course, I didn’t search for several days straight!) the CD packaged with the camera was finally located and I proceeded to install the software that came on the CD on my Mac OS X system.

Now the astute among you have probably already picked up on the second warning sign. (The first, by the way, was that Panasonic did not provide a way for iMovie to import movies). For the rest of you, here it is:

    Mac OS X Applications do NOT use installers!

Having used software for other cameras, this was the first that required an installer to put the application on my Mac and I was fairly annoyed about the requirement. Annoyance became outrage / disgust when I discovered the installed software:

    a) is useless, in comparison to iPhoto a complete joke. Supposedly “native”, but looks, response and general feel were as good as a very (very) poor java application. If this is the best that Panasonic can deliver their company programmers need to be fired!
    b) has no ability to import video from the camera. Yes, that’s right—a camera that advertised right on the box that it is “fully compatible with Mac OS X” has absolutely no way to import movies from the camera under Mac OS X. Hell, for all I know Panasonic doesn’t allow importing movies under Windows either!
    c) is intrusive, acting like a trojan or virus, and can NOT be uninstalled! WTF?!?!?! Yes, that’s right … the software puts in all kinds of crap into your system, like this little gem: a system extension (I’m assuming since I can’t find the app in the Applications folder or in the process list) that puts a banner add on the top of ALL of your other windows! No closing it either, in fact since it’s a system extension you can’t even quit it! Panasonic: this is not how applications operate … this is how viri operate!

Item b is upsetting because I expected to be able to use this camera for taking photos and movies; but being unable import movies them makes the movie taking feature useless. It means I spent hundreds of dollars on a camera that I can’t use as expected.

Item c is unacceptable; installing virus-like software simply should not done, ever! I’m literally at a loss for words here … how the fu*k did Panasonic’s management OK this???

More Software Details
Panasonic’s software package is distributed under the label “ArcSoft”. Maybe this is a Panasonic label to distance the parent company from such crappy software (and that’s ignoring the whole virus install, and taking efforts to make the software uninstallable!) or maybe it’s a 3rd party software package they’ve licensed, but it doesn’t matter because the responsibility for Panasonic’s end-user experience is 100% the responsibility of Panasonic.

There were two programs: MediaImpression and Panorama Maker. Both programs are delivered as installers instead of Mac OS X standard applications. However, as far as I can tell there is no need for this because the applications themselves, while poor examples of commercial software, are completely self-contained and I could simply copy the application bundles to other computers where they would run just fine.

So, what’s the purpose of the installers then? Obviously, the only purpose is to install the virus-like software! Way to go Panasonic, your company is obviously run by stand-up guys who are truly concerned about their customers..NOT!

Since I have not been able to locate a means for getting rid of Panasonic’s virus/trojan software, I would be very appreciative if anyone can give me any help on removing this trash!

Again, it doesn’t matter whether or not Panasonic wrote this software or licensed it, they put it on their CD under their name, and their printed instructions direct you to install the software in order to use the camera, so the end result is that Panasonic put this crap on my machine.

My Options?
So far the only way to import movies from this camera involves purchasing a 3rd party software solution. Unfortunately, the only program I can find seems extremely suspect! It’s “website” is suspiciously similar to the ArcSoft site, and it has multiple products which appear to be there only for the purpose of bogus search results, because only the titles change … the product descriptions and screen images do not! In fact, they look a lot like the ArcSoft software screens. Furthermore, there a several bogus “articles” about how to get video from Panasonic cameras into Mac OS X, all of which recommend this software. And all those articles are on websites which have a nearly identical look to the website which sells the software the article recommends … and those websites also have no other content, except for lists of free software that do not compete with anything the “recommended” software’s site sells.

All this goes to my pretty much being guaranteed not to purchase; not only am I reluctant to be forced into purchasing software to perform functionality that was advertised as being included in the product I originally purchased, but even under ideal conditions a website setup like that screams “virus infection, credit card information stolen, sell and/or spam my email”, or some other undesirable result if you initiate a purchase and/or contact of any kind. After Panasonic has already installed trojan / virus software on my computer, I think it goes without saying that this site rates at least 99 out of 100 on a scale of likely to end up not being in my best interests!

So, any one have a way to import video from a recent model Panasonic camera? (My specific model is a Lumix DMC-ZS3)

Summary
The software included on Panasonic CD’s installs extremely invasive “pop-up” programs that are installed in a manner designed to make them as difficult to remove (uninstall) as possible. That’s virus behavior, not application behavior, shame on you Panasonic!

Concusion
Unfortunately, I must advise, in the strongest possible terms, to avoid purchasing any Panasonic cameras until they remove the trojan / virus installation(s) and provide software that is truly usable in performing the actions Panasonic advertises as being included with their cameras. This is really too bad, because the camera itself is great; movies shot in a moving car at high speed on very rough terrain came out great, it even handled 1.2+ G braking/turning. And the digital zoom is great, especially because it’s combined with a very nice wide angle lens. A great combination of hardware that gets trashed by the software side.

Say, Panasonic hardware people, you really need to talk to the guys on the software side, as well as upper management, because those software people (replace people with your favorite cuss word, I did) are ruining your excellent work!

First photos of updates to S2000

Posted on : 31-10-2009 | By : Lane Roathe | In : Honda S2000, Photo Album, featured

Tags: , , , , ,

0

Well, I updated the S2000 again, only this time it wasn’t for performance, rather it was on appearance. :wow: There is still a few things I want to get done, but for the time being I’m “finished” mucking with it. Time to get to the track and step on the gas :)

S2000 Engine Bay post cleanup

S2000 Engine Bay post cleanup

The engine bay came out really clean! I also had the front hood customized & re-painted along with the front fender and both front side fenders (as all three had various dents, scratches and other unsightliness).
S2000 Hood

S2000 Hood

I see very few after market hoods that I like, and good fitment seems to be a mostly miss in all cases. Instead, I had mine customized, which ended up costing about what a good custom hood plus paint job (don’t like the CF look) would have cost.
S2000 gauges

S2000 gauges

I had a pillar pod setup on my first install, and really hated it; blocked too much of my view (esp. during an autocross!) and advertised “boosted” too loudly. So, a bunch of custom work later and I have something that looks very much like it could be stock. I like.

Snow Leopard Breaks All 3rd Party Apps by Removing Creator Codes!

Posted on : 10-09-2009 | By : Lane Roathe | In : Development, Mac OS X, Rant, featured

Tags: , ,

0

Begin RANT

OK, so the title is a little sensational … but this decision is going to cost me money, so I am understandably upset. It’s also a decision that seems to have no merit, and if rumor is correct was simply more of the NeXT clan forcing out any traditional Mac OS X functionality out of ?spite? … I don’t know why, but many of these decisions seem to be “NeXT is correct, Mac OS was wrong” vs. rationally motivated.

What has happened

For some unknown, apparently arbitrary reason, 10.6 no longer obey’s a file’s creator code. What this means is that it is no longer possible to attach a document to specific applications from code! I’ve tested creating documents in hexedit, bbedit, etc. and the documents created refuse to open in the creating program when double-clicked. It appears that they now belong to some ‘default’ program (textedit in bbedit’s case).

Is Apple trying to put all other software makers out of business?

I mean, if an end user creates a document in MyWordProcessor but it opens in TextEdit all of the time, which app are they going to keep using? This seems like a really sneaky way to pull of the same “integrate the web browser into the OS” crap that Microsoft did with Explorer. (OK, it probably isn’t, but it sure feels that way to a developer who now has to deal with, and pay for the handling of, hundreds of support issues.)

Seriously, this is incredibly broken!

The inability of programs to create documents that can be re-opened in the creating program by double-clicking on the document icons is a serious problem for both end users and developers. I’ve tried explaining this to various HexEdit users, but they only understand that it no longer works.

Beyond the document creation issue, the loss of this functionality removes a very valuable component from the Mac OS X filesystem. Creator codes, along with their associated data types, offer are _extremely_ valuable in Mac OS X and are one of the really great ways in which Mac OS X sets itself apart from Windows, linux, unix, etc.

Please, let us know what we can do to get Apple management to see the consequences of this decision so that they can restore a very marketable and valuable feature to Mac OS X.

Summary

Without this ability, I am finding that I am very annoyed, to the point of almost hating to use the Mac OS X finder, as so many things like opening documents works the way it used to. How irritating would Apple’s management find it if they had to go through three steps to open every document they worked on instead of simply being able to double click on them?

What Can We Do?

I am not sure we can do anything, but at the very least everyone who reads this needs to file a bug report and submit feedback against 10.6 via the official Apple channels:

Official Apple Feedback Form
Official Apple Bug Reporting Form

If anyone else has suggestions on ways to get Apple management’s attention on this, speak up!

End RANT

UPS continues tradition of poor service

Posted on : 14-08-2009 | By : Lane Roathe | In : Rant, featured

Tags: , , ,

0

Warning, rant ahead! I don’t like posting such, but UPS is making my life miserable often enough that I feel I have to.

Anyway, I purchased a product recently which the company shipped via UPS with a signature required. I’d rather they have used someone else, but it wasn’t a choice I saw available. Since I work and my wife is visiting relatives this week no one is available to accept the package, and my work currently does not have a receptionist but does have a locked door, so no deliveries there.

So the only way I can get it delivered is to pick it up at the UPS customer “service” center. This is where my days get very bad.

What to expect from trying to pick up a UPS package:

1. You will stand in line for hours while waiting to get your package. (Today was 2 hours in line and 1 hour travel time wasted. I needed to be getting actual work done, mowing the yard, anything else but using 1/4 tank of gas and standing around).

2. You will not be able to actually pick up the package, even though you have called and scheduled a will-call pickup and been guaranteed that the package will be available between such and such times. So far UPS has had a package for me about 1 out of 10 times. That’s so f’n bad it’s not even funny. FedEx and DHL have a 100% rate as best I can recall.

3. You will have no recourse, and will be completely unable to get any contact information or a phone # in order to try and resolve the issue. Their attitude is “too bad, try again”. Today there were a dozen people in my situation, which is completely unacceptable. All but a few had called ahead to get a guaranteed will-call pickup arranged, and we had all gotten the ‘confirmation’ callback.

I often have to pick up packages because no one will be home to accept the package. Incredibly, with UPS the situation is even worse because they seem to never be able to find my work space. They claim “the office doesn’t exist”, and are totally flabbergasted that FedEx and DHL can (or could in DHL’s case) find it without any problem. So, every time I have to literally fight with UPS to get my ^R*&^W#%$*^& package.

I’m going to have to call and cancel this order because I can’t figure out how to actually accept the package meaning it’s going to be returned to the merchant. I simply will not waste another three (3) hours standing in line (and driving time) to be told the same old “we don’t know what happened to your package” story by incompetent UPS employees anymore.

This will cost the company shipping (because, of course, UPS isn’t going to own up and cover their costs!) and other misc. fees.

BOTTOM LINE: if you are going to ship a package, don’t use UPS!

Of note, my company (Ideas From the Deep) long ago stopped using UPS to send our customers orders because a) they could not meet express mail guaranteed times, b) lost packages, c) damaged packages and d) were costing us a lot of money in refunds, bogus shipping fees (I consider a shipping fee bogus if the package never arrives or arrives past the guaranteed date).

When is a WebOS “OK”?

Posted on : 21-07-2009 | By : Lane Roathe | In : Development, featured

0

So I’ve been wondering for a while now as product announcements get made and the online and press communities react: when is a WebOS a good thing?

Specifically, for instance, when Apple first announced the iPhone, it provided developers with a WebOS based API set for delivering applications to end users, including the ability to run multiple applications at once. This was immediately trashed by just about everyone.

However, when Palm announced they were ditching their traditional c/c++ based OS and replacing it with a WebOS, the same people who trashed Apple for the same decision were gushing over what a brilliant move Palm was making. And they are equally thrilled about Google’s WebOS announcement.

Perhaps it was because Apple didn’t try and come up with a clever marketing term (ie, WebOS) and instead just called it what it was, a development environment based on a Safari. Both Palm and Google are providing exactly the same thing, a traditional OS at the core with a sophisticated web browser as the “operating system” that the end-user and developers are sand-boxed in.

I’m not saying that a WebOS is not a good idea, I thought that Apple’s offering was pretty nice but admit that I wasn’t interested in developing for it until the Obj-c/c/c++ API was announced. By the exact same token, I’m not really interested in developing for the Palm or Google offerings for the same reason; the type of apps I develop are not that interesting from a developer standpoint on WebOS based API’s.

What I’m really wondering is why sometimes the general opinion is that a WebOS is great and other times the same general opinion is that a WebOS is terrible.