I have been known to tweet @jspies

my current Work Stack

  • iOS Objective-C
  • Ruby
  • Mongo
  • Rails/Sinatra
  • jQuery
  • Capistrano
  • Passenger
  • Apache.Nginx
  • Heroku
  • Nodejs
last edited 02.10.2012

here's all my posts so far

02/10 Using the Facebook SDK in an IOS Static Library
04/11 Managing Development or Sometimes work gets in the way of work
12/21 Git Stash: For when your boss|clients|life priorities change
12/09 Picker Fields in Titanium
11/30 An Update on Raphael JS and Charts
10/08 How to make a Native App Form that doesn't suck with Titanium
09/23 Notification Subscriptions in Gowalla
09/21 Developing an API in Rails
08/26 I was promised Event Driven APIs and hoverboards. Where are my hoverboards?
08/14 A Node.js wrapper for Gowalla
08/09 Phusion Passenger Tweaking: Apache stuck in Sending(W)
06/28 HTML 5 is here and breaking old hacks we should have never done!
06/26 Simple PDFkit example in Rails 3
06/23 Raphael.serialize
06/12 Serializing RaphaelJS
06/11 Rails 3 beta4 destroyed my Tie Fighter
05/21 Rails 3 and Shoulda
05/13 Using yaml to configure default options for Paperclip
05/07 It's OK to not be pretentious
04/23 Snippet #1
04/21 I Need Closure
04/16 The Good and Bad of Github
04/08 Fun with Beards, or at least mine

Using the Facebook SDK in an IOS Static Library

The new Facebook SDK is great. The Single Sign on is a much more fluid login process for the majority of Facebook users. But the old dialog, despite being ugly, let us put it anywhere, without any problems.

We have a static library that uses Facebook, that our partners can drop into their own app. The new SDK causes some problems. If they are already using Facebook, the methods in the App Delegate collide. Even if they aren't using it, you have to convince them to update their plists with your schemes.

Facebook seems to have forgotten to put some options into the new SDK, but if we take a tour through the source code, we see this method:

1
2
3
4
5
- (void)authorize:(NSArray *)permissions {
  self.permissions = permissions;

[self authorizeWithFBAppAuth:YES safariAuth:YES]; }

Changing those two YES's to NO's makes the app revert to the old dialog. No plist entry needed, no entry points in the App Delegate, just good old web view callbacks.

The only problem for us is that distributing the Facebook SDK with our library would cause headaches for our partner's developers. They would have two clashing FB SDK's.

So we expose the method we want and create a category to write a new method using the private method authorizeWithFBAppAuth.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// expose Facebook API we need
@interface Facebook (Private)
- (void)authorizeWithFBAppAuth:(BOOL)tryFBAppAuth
                    safariAuth:(BOOL)trySafariAuth;
@end

// Facebook category for extending @interface Facebook (Bypass) - (void)bypassAuthorize:(id<FBSessionDelegate>)delegate; @end

@implementation Facebook (Bypass)

- (void)customAuthorize:(id<FBSessionDelegate>)delegate { // you can set your own perms here _permissions = [NSArray arrayWithObjects:@"email", nil]; _sessionDelegate = delegate; [self authorizeWithFBAppAuth:NO safariAuth:NO]; }

@end

I just dropped that in the controller where I needed it, although you could always include it from its own source files.

blog comments powered by Disqus