04

Sep

iOS Twitter integration stopgap

I think it's fair to state that most-if not all-iOS developers are excited about iOS 5.0's OS level integration with Twitter. While we wait for iOS 5.0 to arrive and for users to upgrade, integrating Twitter into an iOS app can be done in one of two ways.

One: the purist way

The purist way is to use Twitter's strict OAuth 1.0 support to enable the user to login to twitter using a webkit webview from within your app. Doing this usually requires using a half-baked open-source library (if you can call it that) to manage the webView and strip

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

10

Oct

Mocking paperclip with rspec

When using the S3 method of storage for paperclip, the last thing you want is to incur extra charges just for running your tests.

If you want to simply mock the storage aspect completely, and I'm not saying you do, but *if* you do, just do this:

@your_model.should_receive(:save_attached_files).and_return(true)

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.

10

Mar

Rails 2.3 Templates - A small tip

Pratik's HOWTO for Rails 2.3 templates is pretty thorough but did not include support for something I needed to do.

What I found is that I wanted to install a number of gems in a template. Simply adding the gem like this:

 gem 'term-ansicolor' 

resulted in an error!

 rake aborted! A key is required to write a cookie containing the session data. Use config.action_controller.session = { :key => "_myapp_session", :secret => "some secret phrase" } in config/environment.rb 

Before trying to hack up my own solution to add this line to

07

Mar

Agile.....and fun too!

Most if not all of your readers are familiar with Agile methodologies. While I thoroughly understand the values of Agile development, I've always had my beef with projects that follow them religiously. To me, there are other ways to ensure your project is delivered on time and works like it should. Particularly, methods that are more fun and dynamic.

Personally, I hate the idea of avoiding problems by putting bureaucracy in place. That's what the Agile methodologies are to me. Coding bureaucracy. They are methods of avoiding problems ahead of time, by putting artificial checkpoints in place.

What's the

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