16

Jul

Easiest way to download remote files for iOS

I updated and open-sourced a utility for downloading web-hosted files for iOS today. Using it is extremely easy and doesn't require any notifications or delegates. Only sexy block syntax.

First, you'll need to import it in your implementation file:

 #import "RemoteDataManager.h" 

Then you can:

 NSString *location = @"http://tailsmagazines.files.wordpress.com/2009/04/kitten.jpg?w=320&h=480"; [[RemoteDataManager sharedManager] getDataAtLocation:location withCallback:^(BOOL waiting, NSData *data){ if(waiting){ // if the data is not cached [loadingIndicator startAnimating]; } // when the data is available else{ [loadingIndicator stopAnimating]; imageView.image = [UIImage imageWithData:data]; } }]; 

The key thing to acknowledge here is that the Callback block may get

17

Jun

Konstructor: Easy TableViews for iOS

Creating TableViews is one of the many very verbose tasks in iOS development. Every attribute of the table and the cells has to be customized by implementing a different protocol method.

Not anymore

Thanks to the magic of blocks, the overly terse task can become something declarative, readable and even fun!

Here's an example of what it can be with Konstructor:

 self.tableCellHeight = 100.0; /* Create an array of data. You'll likely do this completely differently */ NSDictionary *gloves = [NSDictionary dictionaryWithObjectsAndKeys:@"Gloves", @"name", @"for your hands", @"caption", nil]; NSDictionary *muffs = [NSDictionary dictionaryWithObjectsAndKeys:@"Muffs", @"name", @"for your ears", @"caption",

10

Oct

NSOperation and NSURLConnection conflicts

The right way to use NSOperation, NSOperationQueue and NSURLConnection

I stumbled across a problem today when trying to make an asynchronous POST request to a server.

I created a request class by subclassing NSOperation and was calling it by adding it to an NSOperationQueue (more here) and within this class's (void)main method, I was creating an NSURLConnection like this:

 NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self] 

The problem I was experiencing was none of the NSURLConnection delegate callbacks were being fired.

After a little research I realized that when you create an NSURLConnection using the initWithRequest

26

Aug

NSXMLParser doesn't fire - (void)parserDidEndDocument:(NSXMLParser *)parser

Today I ran into an issue where an NSXMLParser would not fire the parserDidEndDocument delegate method. I was parsing XML stored locally and it turned out to be an issue with a trailing newline at the end of the document.

To fix it, I made sure there was no newline at the end of the final closing XML tag. This seems lame of NSXMLParser or is there a convention I am just not aware of?

Nevertheless, I hope this helps someone.

30

Jan

MPMoviePlayerController comprehensive method list including undocumented

For your iPhone Media Player hacking pleasure:

 "- (@) _localizedDescriptionForErrorCode:(i)arg0 ", "- (@) _volumeAudioCategory", "- (@) backgroundColor", "- (@) contentURL", "- (@) init", "- (@) initWithContentURL:(@)arg0 ", "- (@) movieView", "- (@) videoViewController", "- (c) hideLoadingIndicatorForLocalFiles", "- (c) isFullscreen", "- (d) currentTime", "- (I) _visiblePartsForMovieControlMode", "- (i) movieControlMode", "- (i) orientation", "- (i) scalingMode", "- (v) _audioRouteChanged:(@)arg0 ", "- (v) _bufferingStatusDidChangeNotification:(@)arg0 ", "- (v) _createPlayer", "- (v) _expireImplicitAudioRouteChangePlaybackRestart", "- (v) _itemDidChangeNotification:(@)arg0 ", "- (v) _itemFailedToPlay:(@)arg0 ", "- (v) _itemFailedToPlayMainThreadCallback:(@)arg0 ", "- (v) _mediaServerDied:(@)arg0 ", "- (v) _mediaServerDiedMainThreadCallback:(@)arg0 ", "- (v) _movieDidDecode:(@)arg0 ", "- (v) _movieDidDecodeMainThreadCallback:(@)arg0 ", "- (v)

25

Jan

iPhone: Custom gestures on your UIWebViews

Okay, so you saw Brandon's tutorial on creating a web browser using UIWebView. If you've played around with webviews enough, you've probably wanted to get some native gestures going on for your webpages. Let's say you even went so far as to subclass UIWebView to catch the touches methods and were unsuccessful. Here's why.

Let's pretend we have a horizontal bar that scrolls using javascript. You'll need to subclass UIWebView and add a subview to it that lays on top of the scrolling area. You'll catch the swipe gesture on the subview and execute some javascript to fire the

24

Jan

When rails devs go iPhone

I don't know what's up with that title, but it sounds good.

I recently installed ruby/rails on a mactop that didn't have it yet.

I always build ruby from source because, well, I like to. From habit, I always build it in /usr/local. No harm right?

I wish

Said mactop is primarily an iPhone dev machine and check out what happened when I tried to build a native Objective-C app (not rubyCocoa):

error: can't exec '/Developer/Library/Xcode/Plug-ins/CoreBuildTasks.xcplugin/Contents/Resources/copyplist' (No such file or directory)

You might think this is because this copyplist file is not there or has incorrect permissions, but it's

14

Jan

iPhone: Reading data from plist files

A great way to store dictionary data that does not change during runtime is in a .plist file. Say you want to organize some data hierarchically or you want to store the navigation structure of a drill-down somewhere more convenient (see drill-down save example in apple docs), then a .plist file is a great way to go.

Being that I'm such a ruby-dork, I immediately compare this to a YAML file, and it's a good comparison for the rest of you ruby/rails dorks.

Here's a quick example of how to restore data from a plist file. I'll use a plist