Benefits to Proxying APIs Using with Your Own Servers

Last night I was hacking away at some new features in EraseUrX and I ran into, what I still don't know is, a coding error on my part or incomplete api with Facebook. At this point it really could be either one. I am using their graph api and have no problem authorizing a user, requesting extended permissions and getting a list of friends from that user.  However, when I try to post a message to someone else's wall I get an OAuthException message that Facebook couldn't authorize the application.  WTF?! I thought possibly that my access token was invalid or that my url that I was posting with was incorrect. Nope they are fine. I tested it using curl and the post went through just fine with the same access token. After a few more code changes to no avail I decided to approach it from a different angle.

Though most big services take a lot of pride and care in their API's that they produce they still inevitably change method names, authentication schemes, parameters, validation, etc. This type of uncertainty isn't easily managed when you have compiled code on a device.  If/when a service provide decides to change/delete something from their API, your app could possibly break leaving the users pissed and blaming you.  Even though it TECHNICALLY isn't your fault, developers should take ownership and responsibility to do whatever they can to provide applications with the best user experience.

I decided that I would create a small webapp/script on my server that would act as a proxy or broker between api calls from my app and Facebook. On the surface it looks like it is overkill, but the benefits definitely outweigh the overhead.

A standardized output
Depending on if my request is successful or not to Facebook I will get a different JSON response which is fine, but the JSON structure is also different.  If I were do to all response checking on the phone, not only is it EXTREMELY verbose, but I don't want to have to parse through two different object graphs.  Instead my webapp will get the respone(s) and create a standard response structure of my choice. Something like this:

// Success
{
  'status': 'success',
  "data": [
      {
         "name": "John Doe",
         "id": "55555"
      },
{
         "name": "Jane Doe",
         "id": "6666666"
      }
  ]
}

//Error
{
  'status': 'error',
  "data": [
      {
         "message": "Bad error message",
   "title" : "Bad error message  title",
         "type": "666"
      }
  ]
}

Having a standardized response my app code looks for an exact value in the json string, 'status', and transverse the rest of the json response and process everything accordingly.  Efficiency.

APIs Change
As stated above service providers (Facebook, Twitter, Google, etc.) can/will change their api at any given time.  It is by far easier to change code in a webapp, test and deploy then it is to modify code, no matter how well written it is, in a native device app.

Better Monitoring and Logging
Having your native apps hit your script will allow for better monitoring of a) how many user's are actually using your app b) if there are errors you can track down them down easier and faster c) more accurate analytics that are based on your use cases.  In addition, being able to integrate those stats into other business initatives and integration points.

Result Caching
I would bet that companies like Facebook are caching result sets for a better/faster response, but we will never know and to the full extent they are caching.  You can setup your own caching architecture that will best serve you and your apps needs supplementary to whatever may or may not be provided by the service.

Disaster Recovery
We have all seen the Twitter "fail whale" which means that ANY app trying to utilize that API is housed for x amount of time, which is not a good thing.  Having your own server side script would allow you to handle those unfortunate instances when the service is unavailable by using a cached copy of the result set if one is available or send back a message in your standard response that allows your app to present to the user that that piece of functionality isn't working at the moment.

By handling the majority of the requests/response on my server I reduce the amount of boilerplate code/frameworks that are in my iPhone/Android/Blackberry app, able to standarize the message format for more efficient parsing on the device and provide a better user experience.

Why HR Should Take a Lesson From Posterous

This Friday my wife is graduating from Christian Brothers University with her MBA.  It has been a long road over these past few years, but she emerged victorious. The next chapter in her life is to move her current consulting career back to corporate America and it is interesting to see that process again...and when I say interesting I mean SAD and PATHETIC.  It amazes me just how unusable these online job applications are. First she is asked to create an account on CompanyXYZ's site as if it is some online community that she will be frequenting often and sharing recipes with friends.  Second she is asked for her personal meta information, Name, Address, etc. and in some cases her SSN (which no one should ever give unless they are given a job offer and the company needs a background check) and then she has to enter in all of her previous employment, education and then FINALLY upload her resume.  Some want the resume plain text, some require it in PDF or DOC.  Nothing is ever consistant.  All of this is redundant and unnecessary.  You want someone's contact information, it is in the resume.  You want someone's previous work history, it is in the resume.  You want someone's qualifications and awards, IT IS IN THE RESUME.  Why does an applicant HAVE to give you this information again?!

I won't go into all money and time that is wasted when companies purchase these monalithic systems, but I will emphasize that the employment applying process should be about the user.  You may have a great company, but your online application system sucks and probably turns away more qualified applicants than you realize.

HR needs to take a lesson from Posterous.  If someone comes to your site to apply for a job then all they should have to do is email jobs@companyabc.com with the subject as the job title/number.  Your back end system should then parse through their resume and extract relevant information to put into your system for further review and processing.  The first argument I always hear against using email is "Not everyone's resume is a format that is standard that we can parse".  While this is true my responses are a) partner up with Monster.com or Linkedin.com to where all the user has to do is pass in their username for those services and consume a service from the providers who will have their information in a standard format b) hire decent developers who actually know how to program and write the appropriate algorithms to search for headings like "name", "contact", "experience", etc.  If handful of guys at Posterous can parse email, like this one, from every known mail client in the world and post it to a blog I am sure that a resume should be possible as well.

Facebook Graph API with a Native iPhone Application

One of the biggest gripes that I have with working with the FBConnect iPhone SDK, and really the Facebook API, in general was having to deal with a very inefficient REST implementation.  Callback after callback, protocol after protocol, major bugs (that have yet to be fixed as far as I know), and my biggest issue is the nasty user experience having to login a user.  I was very excited to hear when last month Facebook announced they had came out with a new API that would allow great security, ease and flexibility.  The pains of having to go through currently working functionality and refactor the code to accommodate the new features wasn't too much of a problem for me because it would mean a reduced code set on my part and I would be able to get rid of the Facebook Connect SDK.  I set out to test my theories and functionality via a quick web app.  No problems.  Then I proceeded over to my native iPhone app.  EraseUrX v2.0.  The new authentication mechanism utilized in Open Graph is OAuth2.0.  While many of the headaches and complexities of using OAuth are addressed and the documentation for using it in a mobile web app are well documented with Facebook they TOTALLY dropped the ball on providing any direction on using it with a native iPhone app and they don't provide an updated SDK.

I could one of three things: 1. Use the old Facebook Connect which should still work for the forseeable future, but as stated above has too many issues that I don't want to deal with and they could drop support at any moment. 2. Wait for Facebook to publish a new SDK, but how long would it take them 3. Just figure it out myself and have a flexible solution that didn't relay any third party framework.  I went with option 3.
The first thing you need to do is setup your app with Facebook.  Second, you will need to create a "callback" page that Facebook will send the request back to once the appropriate code and token has been given to your original request.  Third, once you have gotten the access_token from Facebook then you need to put it in a DOM object. This is important so that you can retrieve it via the UIWebview's javascript string evaluation and then finally save the access_token in NSUserDefaults for any subsequent requests.  In my case I wanted to get a list of the currently logged in friends.  Instead of having to go through the callbacks and delegate methods associated with the FBConnect SDK I now have user's login via OAuth and I make a call to, https://graph.facebook.com/me/friends, and get a JSON response of what I need.  Simple. Beautiful.
Callback Example (PHP):

Custom ViewController (I am not including setting up the uiwebview. I assume you already know how to do that):


Create Custom Sized UITableView with Header and Footer Views

I am currently working on a photo gallery/slideshow app and one of the requirements is for the main gallery listing page to have static header and footer that shows the app name, contact information and adverts.  The logical first method of attack is to just setup a UITableViewController subclass, slap some views and subviews to the table view header and footer and get on with the day.  However, the table itself should scroll, but the "header" and "footer" views should remain stationary.  My first approach, I found out quickly, did not work.  Surprisingly, there are a lot of people having issues with custom sized uitableviews in general and the discussions that I saw online didn't provide a very straight forward solution so I decided to create one.

The first big problem that most people run into is that they can't seem to resize the uitableview no matter what frame size they set.  It doesn't matter if you do it programmatically or through Interface Builder it still takes up the ENTIRE screen.  That is because they have subclassed UITableViewController.  To be honest I am not sure that happens "under the covers", but the custom frame sizes/locations are ignored.  You must make your controller a subclass of UIViewController and then add your UITableView as a subview to the your controllers view.

For example:

At this point your frame size and height will be respected.

In my example I setup a simple UINavigationController project with two controllers.  The first has a header view, footer view and uitableview.  The second "detail" controller just has a UILabel with placeholder text.  Everything is built programmatically so that you can adjust frames and positions easily as well as any other customizations you would like.  Comments/suggestions are always appreciated.

Download Project

I Will Not Ride the Dell Lightning

Being that my passion for development and design are usually centered around mobile apps I am always interested in any new platforms and handsets that poised to make any impact on the current market.  As such I was really interested in the article posted over at Engadget yesterday: Dell Lightning: the ultimate Windows Phone 7 device leaks out. However, my enthusiasm faded after the first sentence and twindled down to zero by the end of the first paragraph.

"Hot damn, people. The mother of all Dell leaks just dropped into our laps, and the absolute highlight has to be the Lightning, a Windows Phone 7 portrait slider."

I can overlook the fact that the device is running Windows and some of the on screen usability issues because I haven't used one, but what bothers me the most is that handset manufactures can't seem to understand handset design.  This phone is presented as having a "revolutionary" device design, but once again you have the same tired, inefficient slide-the-handset to show the qwerty keyboard.  Really?! That is the best you have. That is NO different from all the other handset designs that are offered by ever manufacturer in the world for the past 5 - 10 years.  Dell and Microsoft combined have more money than most European countries.  Why they don't or can't find/recruit/steal the BEST designers and developers to come out with a real competitor to the iPhone is beyond me?  However, what this does mean that within 6 months of this device launching you will see it sitting next to the Dell MP3 player that was supposed to be so great.

Looking over some of the other features that the device offers, once again there is nothing that I can't get, and probably better, with an iPhone or Nexus One.

::NOTE::

When I was attempting to find a link to the dell jukebox from their website it didn't come up.

To Kill A Mocking Bird Called "Your Twitter App"

Over the past week there has been quite a bit of news coming out of the Twitter HQ. First it was announced that Twitter has acquired Tweetie and subsequently hired it's author Loren Brichter.  They also have launched the promoted tweet service and for you real bird watchers out there the ability to add meta data to tweets using the API.  Finally, it was confirmed that Twitter is going to launch their own URL shortener and stop using bit.ly.  A recently published article on Mashable summaries one tech startup's frustration with the announcement of Twitter now coming out with it's own "official" Twitter client. Why is there so much frustration? Because developers, at times, feel they have been sabotaged by the very companies they are using.  Just to be clear, they are upset because a service that Twitter owns, that they allow developers to use for free, is now being used by the very company that created it in the first place to promote their own brand!

I'm just saying...

I am developer and know what it is like to have that great idea or great app and to have some MUCH bigger/better company come along and launch their own version which inevitably kills mine before it got off the ground.  However, those are the ropes.  Don't put all your "1"'s and "0"'s into one app or service.  That goes for everything in life.  This animosity towards Twitter, and any other information service, is quite misdirected.  As mentioned earlier, Twitter didn't go out and build their own app, they chose, quite possible the best Twitter client in the AppStore today.  Did developers really expect Twitter to NOT have an official app.  I am surprised it has taken them this long.  That is like Apple releasing the iPod, but not iTunes.

What does that really mean? If you create something that is TRULY great then there is a good possibility that it will get picked up.  Just look at all the startups and other mashups that have been acquired by big companies lately. Twitter has just released a site for developers that will aid the creation of new mashups and services to use with the information they provide not hinder innovation.

It is an unfortunate price that one has to pay when the service you rely on for your mashup comes out with their own official app that does the same thing and my sympathies are definitely with you, but if all you do is rely on that ONE great idea then you weren't going to last that long anyway.

Creating Custom Glossy Gradient Buttons Programmatically

As my experience, and hopefully skill, in iPhone development has matured over the past year and half I am in the constant search for the best techniques for my apps to run better, faster, and consequently more efficient.  Of the top developers that I follow they all make references to the importance of utilizing subclasses of UIViews and the underlying subsets of views in general.

I love the UI elements that are used on the phone. I didn't realize the awesome power of CoreAnimation and the flexibility that it gives you to manipulate and create graphics as such a granular level.  I set out to see if I could recreate a common iPhone UI element completely programmatically: a glossy gradient button that still responds to touch events.

The end result was a success and a great learning experience.  I still need to add in more testing to make sure that interacting with all these views is more efficient than interacting with standard pngs.

This biggest issue that I ran into was "re-enable" the button actions.

Simply subclassing UIButton did create a problem when dealing with the UIControlEventTouchUpInside/UIControlEventTouchUpOutside methods that you associate with buttons.

I was able to overcome this issue by implementing the touchesBegan and touchesEnded methods.  Remember...UIButton inherits from UIControl, which in-turn inherits from UIView.

Problem solved.

Download Project

Turn by Turn Directions with MapKit and Google Maps

Update - 03.31.2010

I decided that I didn't like the accuracy of the location from the browser.  It is isn't as good as the MapKit or default Google Maps app on the phone.  I added a button the directions page to open default maps application.

One of the best features used in Google Maps is the turn-by-turn directions.  Unfortunately, I haven't seen, and don't even know if it exists without proprietary code, an effective way to show turn-by-turn directions using the MapKit API in the iPhone SDK.  Though Google announced that they have included it in their Android platform they were vague about if/when it might come to the iPhone SDK.  No matter, where there is CoreLocation there is a way.

Goal
Most smaller companies only have one "brick and mortar" location.  So I wanted to show that location on the map and then present the user with ability to get turn by turn directions to their location.  In my example app the marker will show the location of my favorite sushi place in Memphis, Sekisui's Pacific Rim.

Obstacles
No clear way to implement turn-by-turn directions with MapKit using the iPhone SDK.  Though Safari for the iPhone has the ability to get your current location via the browser, i wasn't very impressed with it's accuracy.

Solution
Use CoreLocation to get the user's lat/long and then pass that to a UIWebView that will display a Google Map with directions.  Though in this example I am using a local html that is stored on the phone a better implementation would be to have the file stored remotely and then cached on the user's phone for faster load time.  However, it is important to note that you should "decache" the file if the user's previous coordinates are different then their new current location.

Note
For the best results and accuracy it is better to run this on your device since CoreLocation the simulate will show Apple's headquarters as the user's location.

UIViews with Rounded Corners and Animations

One of the best iPhone reference books on the market today is iPhone SDK Development by Bill Dudney and Chris Adamson, published by Pragmatic Programmers.  The examples are real-world, easy to follow and cover just about any area of development that one needs.  In my earlier projects and example code I tended to use a lot of graphics for buttons and backgrounds because I need something with rounded corners and/or a gradient.  However, in my latest project I have wanted to get away from that and utilize CoreAnimation and more UIView drawing techniques and the results have been outstanding.  Load time on my views are much faster because all the drawing and rendering are done on the compiled view level and not from the rendering of an image.

 I created a sample project that loads a three different views onto the controller and animates them.  There is nothing overly complex about the code at all and can be customized to be more configurable, but is written to show the power and flexibility of creating custom views and animations.

::NOTE::
The rounded corner drawing in the project was sample code from the iPhone SDK Development Book.  Credit where  credit is due to Bill and Chris.

As always I encourage anyone who downloads the project to make any modifications and/or enhancements.  For example, you could add in the functionality of firing of the animation based upon text field values or randomizing the speed of the animation.

Google Fiber for Memphis


If I can't get to Google then why not bring Google to Memphis.  The latest project that I worked on is the promotional site to campaign for the Google Fiber project to select Memphis as one of the cities for the it's ultra-fast network infrastructure.  It, by-far, has been one of most rewarding endeavors that I have had the privilege to be apart of.  Not only because of the different technologies that were used for the site (jQuery, Google Docs, Google Buzz, Twitter, Facebook, YouTube, my custom ZF CMS), but also I was able to give back something to the community in hopes of growing not only the local economy, but also foster greater innovation for the rest of the world.

Support Memphis in it's bid for Google Fiber.  Due your small part in something BIG.

http://memphisgoogle.net/site/submit-ideas
http://www.youtube.com/mcan901