Adapting the Facebook API for the iPad

by Christopher Gregory posted on August 9 2010 12:51

So recently I was wrapping up development work with the same iPad app port for Mobile Innovations as I had mentioned in my last post, when I ran across a rather interesting problem.

We make use of multiple APIs for allowing you to share what you’ve made in our Applications with all of your friends. However with the iPad things take on a new dynamic. Before everything would be displayed as its own full-screen view controller but the iPad allows us to focus more into a single view. Popovers are a great way to add extra controls that are relevant to on-screen content but not important enough to take up the whole screen.

We currently make use of Facebook, twitter and email as means for sharing. The last two are relatively easy to display inside a popover. Facebook however, is a bit more of a challenge. The Facebook API, of which they have yet to make a native iPad port, displays a series of procedurally generated dialogs that are meant to take up almost the entire screen. This simply won’t do for the iPad, since it has so much screen real-estate doing something like that would break the design theme of centralizing all the content onto as few views as possible and making use of contextual  items to display related content.

Facebook doesn’t make this easy though. Since everything is generated in code, and not from a xib file, we’ve got to dig around to find the parts we need to alter to make it work. We just need to make a few key modifications to FBDialog.m and we’ll be set. As with my last post I’ll be using the self-defined preprocessor macro TARGET_OS_IPAD to separate the code out, so that the FB API remains usable for either device based on your build target.

First step, sizeToFitOrientation is the main function called to generate the main FB dialog window. We’ll just add this here:


 
I’ve excluded everything after the else, as it’s just the main body of the function. In this case we’re just telling it to set a static frame for all dialogs, you can alter this of course to size it however you’d like. Since all of our dialogs should be appearing inside a view we’ve already set up in the view controller we’ll be presenting in the popover it’s easy to just set a static size. Next:


We need to remove this because we don’t want the facebook dialog to try and re-orient itself on orientation change since our popover will automatically handle repositioning itself. Next we’ll add some important code to our Init function

 



By setting ourselves as the active popover delegate this lets us automatically dismiss any open dialog when the popover is dismissed.
And this goes at the end of dismiss method



The above returns the popover delegate to its original source and removes the FB dialog from our view hierarchy.  It’s important to remove the FB dialog’s view from the superview because otherwise you’ll get a memory exception later when the View Controller tries to deallocate the view again as part of its cleanup. This frees everything up in order so we don’t have anything lingering in memory. Now when assigning and removing the Facebook view your implimentation of the above may be slightly different. In my case my main controller view was given the tag 8426 and 9999 is a container view I created just for the Facebook API dialogs, which I move back and forth in the hierarchy as necessary. For the code to work that also means that the view you're adding the dialogs to must already be a part of the view hierarchy.

Normally you might not see this but there’s a grey border typically drawn along the outside of the facebook dialogs. Depending on your app you may want to remove this. If so just put the following code at the start of the drawRect method like so:


 
There’s still one more part of the code that tries to resize our view. Now, you can either do this the way I did, which was to comment out the body like so:

Using preprocessor statements. Or you can just do it in the add/removeObservers methods, which add the keyboard change notifications. Either way it’s important that the above code doesn’t get called for the keyboard notifications as it’s another point where the FB dialog tries to resize and orient itself according to the main screen.

This last part is from the end of the show method:

 

This adds our dialog to our specified view, and removes the last instances of it trying to dynamically size and orient itself. Now no matter where it appears, no matter what size it is, all of our facebook dialogs will appear inside our special view controller, which in our case will appear inside a popover.

One last important tip. When adding any dialog to a popover, it’s always a good idea just in case to have the top level view as a scroll view with the content size set to the frame’s proper width and height. Popovers will try and move to avoid the keyboard when it appears, and that can cause the view to get shrunk. So using a scroll view will ensure that you can scroll while the keyboard’s up, in case it obscures anything important.

Tags: , , , ,

FBCDN image is not allowed in stream, How can this be?

by Stephen Dewitsky posted on June 22 2010 13:15

The phrase "FBCDN image is not allowed in stream" does not have much meaning to most of the natural world, but to a developer integrating with Facebook features this phrase is a nightmare.  Over the past year we have been developing iPhone apps that will process images in unique ways.  We thought it would be interesting to allow users to share these images with their friends on Facebook, if they have any friends.  The normal procedure is a two part process.  First, a user would upload the image to their very own photo gallery hosted on their Facebook profile.  When that is successful the user could then choose to publish a message to their stream which would include a link to this recently uploaded image.  It was fast and it was fun.

About two weeks ago I noticed that some previously published feeds, and any new feeds, were missing the shared photo.  Immediately I thought there must be a problem with the code.  Let me take a look.  HMMMMMMM.  Everything looks good, but why is the image missing?  Wow, I don't have much time to continue debugging this.  Let me check Facebook Developer Documentation.  Nothing here about missing images.

On the 17th of June 2010 the shock was felt. I was testing a new iPhone app we are working on for in20years.com.  The Facebook integration was complete and I attempted to publish a message to my Facebook profile using a Facebook Photo Gallery image.  The process came to a halt and the dialog read, "FBCDN image is not allowed in stream ..... You can see this because you are one of the developers of the app."  Ouch.  I could indeed see this message and yet I have no idea what it means.  Endless Google searches return nothing.

With shifting priorities in schedule we decided to let this go for the weekend.  Monday morning was a bit more informative.  Facebook Developer Forums erupted in outrage that all existing apps ceased to work due to this error. The official word came through an RSS feed reading:

Serving Images in Stream Stories
Jun 18, 2010 3:21pm

We no longer allow stream stories to contain images that are hosted on the fbcdn.net domain. The images associated with these URLs aren't always optimized for stream stories and occasionally resulted in errors, leading to a poor user experience. Make sure your stream attachments don't reference images with this domain. You should host the images locally.


So what does this mean?  Well it depends on your point of view.  It means Facebook does not have enough consideration for current applications using images in the fbcdn.net domain to grace the developers with a warning of this new policy.  I was experiencing problems for weeks before this statement was released.  It means that developers cannot rely on any implementation of a Facebook API component to behave the way they expect on a day to day basis.  It means that developers must find a way to host their own images if they plan on placing them in a Facebook Stream.  It means we must react with Ninja-like reflexes.

Tags: , , , ,

Contact Us

We want to hear from you.  Our community is important to us and we want to make sure we give you the contact you want.  Please contact our team if you want to sent us feedback of any kind.  Enjoy reading!

RecentComments

Comment RSS