Extended Permissions support in Bamboo (a Facebook Graph API iPhone SDK)

May 31, 2010 at 3:31 pm (Bamboo, Facebook development, iPhone development, Software Engineering) (, , , , , , , , , , )

Today I successfully added support to Bamboo for Facebook’s nefarious new permissions model. This means that, for the very first time, iPhone application developers have real SDK support for Facebook’s new Graph API, without writing very low-level networking code and handling extremely confusing authorization and permissions.

Facebook has been threatening to shut down data access for all apps that do not migrate over to using the new model for some time now. The most recent deadline was June 1, and it has just moved back to June 30.

If your iPhone app publishes to the user’s stream, as is the case for 98% of iPhone apps, your app will break. You need to do something about it NOW, so that you are ready by June 30. And I am here to help you with that.

Enter Bamboo, a Facebook Graph API iPhone SDK.

First, some Facebook permissions details

Facebook’s fundamental permission concept has changed from a simple yes/no, either your app had permission to do everything or nothing, to a much more granular set of very specific abilities. There are currently 5 “publishing” (write) permission types, and a whopping 45 “data” permission types, broken down into personal data (25 types), and friends data (20 types). You can see the full list here.

For iPhone app developers who interface with Facebook, this means that if you do anything besides read the most basic of public data from a user’s profile, you must update your app with support for the new extended permissions.

So, how can Bamboo help me?

In one succinct line: Bamboo aims to meet all your Facebook needs as an iPhone application developer.

Bamboo is an objective-c implementation of the Facebook Graph API, including support for both the new oAuth authorization, and the new extended permissions model. For integration instructions and more technical details, please see the Bamboo github page.

For your convenience, here is a simple example of client code using Bamboo:

	[[FacebookProxy instance] loginAndAuthorizeWithTarget:self 
                                  callback:@selector(finishedAuthorizing)];
	GraphAPI* graph = [[FacebookProxy instance] newGraph];

	GraphObject* me = [graph getObject:@"me"];
	NSString* myName = me.name;
	
	UIImage* myProfileImage = [me largePicture];

	NSArray* thingsILike = [graph getConnections:@"likes" 
                                                       forObject:me.objectID];
	
	// hello world post - update status message to my feed/wall
	NSDictionary* args = [NSDictionary dictionaryWithObjectsAndKeys:
                            @"Hello World, from bamboo!", @"message", nil];
	[self._graph putToObject:me.objectID connectionType:@"feed" args:args];

	// comment on a post
	NSDictionary* args = [NSDictionary dictionaryWithObjectsAndKeys:
                                   @"Bamboo comment test", @"message", nil];
	GraphObject* post_result = [self._graph putToObject:@"post_id" 
                                        connectionType:@"comments" args:args];

	// add a like connection from me to you
	[self._graph likeObject:@"your_id"]

Bamboo is designed to make the transition from using Facebook Connect to using Bamboo as simple, straightforward, and easy as possible. I have reused the login mechanism of Facebook Connect, and reused the same UI look and feel for the new extended permissions dialog, so your users will feel right at home with the new flow. They may not even notice that anything has changed.

The underlying systems are extremely complex, so it’s not possible to hide all of it, but I constantly strive to make the SDK interface as easy to use as possible, and I actively support the library…so if you need something, I’m here to take care of you.

While Bamboo is far from being finished, I hope that you will consider it to service your iPhone Facebook needs. One day, someone like Apple or Facebook may publish an official SDK that makes this project obsolete…but given Facebook’s negligent track record with FBConnect, I’m not holding my breath. And until that day comes, right now, Bamboo is your best option.

Honestly, it’s pretty much your only option.

Thanks
R.

Permalink 1 Comment

iPad Universal app with no nibs

May 5, 2010 at 1:04 am (iPhone development, Software Engineering) (, , , )

I don’t believe in using nib files in my iPhone/iPad projects, not even the magic ones that are generated by the default project templates. So, as I’ve been looking into creating universal apps, I have noticed than no one seems to have published a sample universal project that doesn’t use nibs.

I thought I would take this opportunity to provide such a project, so that anyone who wants to create a universal iPad/iPhone app with no nibs, has a clean template to start from that is already setup with all boilerplate work in place.

The project is a part of my rcloudlib repo on github, I encourage you to take a look at it, I keep it very lightweight and include items I find that need in almost every project I work on. The most recent version of the app template will always be in the rcloudlib/samples/rcuniversaltemplate directory, and will be expanded in the future. If you want a direct download of the .zip of the super-clean version that will never change, use this link instead.

The project complies and runs, in both iPhone and iPad mode. You can run both iPad/iPhone in the simulator, using the steps described here.

If you have any comments, recommendations, fixes, or anything else…I’d love to hear them.

Thanks
R.

Permalink 1 Comment

malloc_error_break, double free, iPhone 3.0…maybe you fucked up NSTimer?

June 29, 2009 at 11:13 am (iPhone development, Software Engineering) (, , , , , , , , )

Yesterday, while working on a client project that had been rejected from the app store, I was doing some initial diagnostics and came across this wondrously useless error message in the console:

malloc: *** error for object 0x529d20: double free
*** set a breakpoint in malloc_error_break to debug

Apparently, when doing the quick cert-signing and testing previously, we hadn’t looked at the console on all of the versions…because this particular error is only a warning on the iPhone OS 2.2.1, and a crashing error on 3.0.  Don’t have any idea why the difference across versions, but it’s there.  So when we ran this on an iPod Touch 2.2.1, it seemed to execute fine, you had to be looking at the console, without being alerted by the debugger…tricky little bitch.

Now, I know what a double free is, but I have no idea where to find malloc_error_break…and Google doesn’t fucking help much, it’s just a bunch of people posting build errors on forums, with no useful responses.  I’m hoping this post will make it up the list, and you will potentially find something useful here, instead of just a cry for help.

So…faced with an easily recurring error, I was pretty confident I could knock it out in short order.  The malloc_error_break message was sort of helpful, but not enough.  I could set breakpoints, and never quite nail down the error…I could break before it, and after it (on 2.2.1)…but not on it.

The useful piece of information in that error message is twofold…one, the double free indication.  And two, more importantly, the memory address of the object. That is how I found the source of the error.  I couldn’t find malloc_error_break, but I could guess which objects might be getting double-freed by looking at the code.  It turned out, the original engineers had written this code to stop an NSTimer:

- (void) stopTimer
{
  if (ptrTimer)
  {
    [ptrTimer invalidate];
    [ptrTimer release];
    ptrTimer = nil;
  }
}

this code, is wrong.  The release in the middle is extraneous, and is what was causing the double-free.  The invalidate call is all you need to stop the timer, the setting to nil is nice for sanity.  I looked at the memory addresses of the two initial NSTimers set during app load, and noted them at the breakpoint right before the crash.  And bam, one of the addresses showed up in the error message as the object that had been double-freed.

So, that was it.  There happened to be about 7 different timers floating around the app, all mistakenly stopped in the above way, so the app was absolutely going to crash, no matter what you did.  Commenting out the release was all it took for me…and just over an hour later, I had the app all ready for submission to the app store.  We sent it in this morning, hopefully it should be done by friday.

Thanks
R.

Permalink 4 Comments

Using custom fonts in iPhone applications

June 13, 2009 at 11:58 am (iPhone development, Software Engineering) (, , , , , )

As any iPhone developer knows, the fonts included on the iPhone can be a bit…limiting.  Sure, they are fine for business and utility applications, but for games and other design-heavy apps, the built-in fonts really don’t get the job done, with MarkerFelt being maybe the only usable, stylistic font.

I worked on typography for just about a decade at Adobe, on such applications as Photoshop, Illustrator, and Flash…so good typographic options are near and dear to my heart.  It pains me to see the limitations that iPhone developers operate with.

What is almost more painful, is the complete lack of a coherent solution from the community.  I spent some time looking around, and found a grand total of 2 solutions, neither of which is complete…but both are usable to some extent.

  1. EasyGlyph – this is a windows only .NET program to create a spritemap out of a font, plus objective-c code to support using the spritemap in your iPhone application.  This solution is good enough for some users, mainly game developers who don’t mind the inherent limitations, and just need some nicely styled text in small amounts.  You are basically just blitting images instead of text, so you are unable to do anything that is not pre-rendered into the images.  Personally, I don’t like this approach, but it would be rude of me not to include it here, as many of you may find that this is just what you need.  It works very well for very simple needs.
  2. A very nice and responsible blogger UIHacker posted this post, which is as far as I can tell, the only fully working solution that anyone had the confidence to post.  It is a very nice packaging up of what is really the best solution right now, which is to operate at the CG* level (CGFont, CGContext, etc).  If you are going to really dive in and use a custom font, this is the way to go.

What I have done, is taken the code that UIHacker posted, and expanded on it…to fit my needs.  Everyone’s needs will differ, but some things are very common.  I will post probably the #1 request I saw, which is how to center text.

  1. To begin, get the CustomFontBase.[hm] from the link above.
  2. in the drawRect() method, look for the line that draws the glyphs, it should look like
    CGContextShowGlyphsAtPoint( context, 0, 0 + fontSize * .25, 
                          glyphs, length );
  3. The second parameter is the x offset, which is what we are interested in.  Replace this call, with the following code:
    if ( isCentered )
    {
    CGContextSetTextDrawingMode( context, kCGTextInvisible );
    
    // draw the glyphs to get the width
    // hack the y-point to make sure it's not cut off below font baseline
    // - this creates a perfect vertical fit
    CGContextShowGlyphsAtPoint( context, 0, 0 + fontSize * .25,
                                                    glyphs, length ); 
    
    // get width of text for autosizing the frame later (perhaps)
    CGPoint textEnd = CGContextGetTextPosition( context );
    float adjustment = ( self.frame.size.width - textEnd.x ) / 2.0f;
    
    if ( isOutlined )
    {
    CGContextSetTextDrawingMode( context, kCGTextFillStroke );
    }
    else
    {
    CGContextSetTextDrawingMode(context, kCGTextFill);
    }
    
    // draw the glyphs for real
    // hack the y-point to make sure it's not cut off below font baseline
    // - this creates a perfect vertical fit
    CGContextShowGlyphsAtPoint( context, adjustment, 0 + fontSize * .25,
                                                    glyphs, length );
    }
    else
    {
    // draw the glyphs
    // hack the y-point to make sure it's not cut off below font baseline
    // - this creates a perfect vertical fit
    CGContextShowGlyphsAtPoint( context, 0, 0 + fontSize * .25,
                                                    glyphs, length );
    }
  4. You will also need to add a member “isCentered” to support both centered and non-centered drawing.  Also, the “isOutlined” section is optional, but I thought I’d include it since it was something else I added.  UIHacker included support for Glow, and I similarly added support for outlined text.  The color of the outline is controlled by the stroke color, which you can set like this:
    if ( isOutlined )
    {
    CGContextSetStrokeColorWithColor( context,
                                       outlineColor.CGColor );
    }

While this is still very limiting, only single-line text is currently supported…it is a very good start, and is very easily extendable to as much functionality as you are willing to code up.  Type engines are no easy task, but I think as long as the community continutes to share and build off each other’s success, we can make good progress.

I am considering putting together a more fully featured version of this and sharing it, if there is sufficient interest in the same features.  For now, I think this is a good enough starting point, that anyone can make good use of it in any iPhone app.

Permalink 3 Comments

What it means to be a “Senior” professional

May 1, 2009 at 3:09 pm (Business, Software Engineering) (, , , , , , , )

In the professional world of engineering, there are certain words and labels that are commonly used, and uncommonly defined or understood. In software engineering, “Module” is probably the most amorphous, ill-defined, appropriate-for-almost-anything term we commonly throw around. VP of Engineering is another one, or Director of Engineering. What exactly does it mean to have that title, and what do those people do, especially in an environment like, say, a company of less than 5 people?

My all-time favorite though, is “Senior Engineer.” Commonly “Senior Software Engineer,” occasionally “Software Architect” (which is a completely different job, but I’ve seen the two used interchangeably by many people), and there is a long list of other variants. The main purpose of these seems usually to be to stroke the ego of the person who is the descriptor of the title, but aside from that, the title’s main purpose is usually to distinguishing them from the ill-fated “Junior Engineer” title or status.

On occasions across my career, I’ve pondered these titles…and often wondered what exactly was it that made someone worthy of one title or the other. It was clear to me long ago that many unworthy people held the title of Senior Engineer, so either everyone else knew something I didn’t know, or my standards and evaluation method was different than those commonly held in the industry.

What really does it mean to be a Senior Software Engineer?

Recently certain events have caused me to reconsider this question. Recent events set one, a good friend of mine, someone who is without any question or debate in my mind, a very, very senior software engineer, was repeatedly turned down by multiple software companies, for failing technical interviews. And when I say undebatably senior, I mean Caltech graduate, IQ 3 to 4 standard deviations above the norm at the very least, 15-20 years of very solid experience, and a well-rounded programming god. You may even know his name. In one instance, the technology in question that was his downfall was CSS.

C.S.fucking.S. The technology that, unless you are going to be a browser UI wizard who just focuses on layout and design, has essentially no logic to it, you just look up the features you want or need at any given time on the web like a dictionary or encyclopedia. And he wasn’t interviewing for a front-end job, he was going for a server-side position. CSS was totally irrelevant to his job, and in my book, is basically irrelevant to just about any engineering job. You look up what you need, when you need it, then forget it. You don’t waste brain-space on CSS, it’s just not that kind of information.

Recent events set two, another engineer I know has similarly been judged to be “too junior” by another handful of software companies. His particular situation was slightly different, he was actually in multiple jobs, and then sometimes politely, sometimes impolitely shown the door…but basically, both he and the previous engineer’s situation look pretty identical in nature. This friend of mine has slightly lower credentials than said engineer above, but not significantly different. I can’t help but feel bad for the both of them.

So I ask myself, how could not just someone, but multiple someones, look at the same engineers as I do, and evaluate them completely differently? There are lots of subjective issues involved in all of these types of situations, but the thing that gets me is that it was never those subjective issues that were the cause of the evaluation…it was the hard facts, the objectively measurable metrics that were used to disqualify the engineers in question in every case. Yes, I know that it’s very common to take a subjective dislike, and mask it with an objective window-dressing to make a lay-off look fair…but I honestly believe that wasn’t what was going on. What I think was happening, is that the standards by which the engineers were being evaluated were totally different than what I use. And I think it was due to the relative seniority of the people who were making the evaluations, in large part if not in full.

What exactly do I mean by that? I’ll start my explanation, by referencing Paul Fusel’s book “Class,” which is a piercingly honest and brutal whirlwind of premises, arguments, but mostly observations about the social mechanisms of modern-day America. The basic premise, is that social status in America is, whether you like it or not, a class-based system, and one’s understanding of what “Class” is, is heavily influenced by the level of one’s status in the system. So, for instance, following Paul’s narrative, lower-class people tend to think that money and “showy” things are a measure of class (think of what the term ghetto-fab really means); middle-class people tend to deny that class exists at all, but when pushed they show a strong belief that class is a factor of one’s profession, education, and knowledge (all things that can be acquired); while upper-class people know that class is something that one can not change, it is something you are either born with or you are not…it is a factor of blood a family. Your family is a family of class, or it is not…kind of like medieval royalty. One very interesting observation that Paul Fusel makes, is that upper class people, especially the very top of the upper class, tend to look a lot like lower class people, especially the lowest of the very low. Uneducataed (why get an education, when you are born into the Rockafeller family? It’s certainly not going to help at your upper-class society parties), uncouth (no need to follow social standards, because you are basically above them), and generally unaware of what’s going on in the world (why keep up with events, you already have everything you would ever want or need). It’s not that upper class people are bad people, it’s that they don’t have any external motivation, because they are born with all their means of survival met…so everything in life can be seen as optional.

Now…take that metaphor, and do a quick translation, of “class” into “professionalism”, and class status (middle and upper) into professional titles (junior and senior) and you start to get a decent idea of what I think is going on in the professional software engineering world. When you have junior engineers (middle-class people) interviewing, working-with, and evaluating senior engineers (upper-class people), they find that the senior engineer in some way does not measure up to their standards (of professionalism, which are all things that can be gained, learned), they come to the believe that the person is junior, and that they are in fact senior – it says so on their business card, and they are better than this other fool who was supposed to be senior, so it seems like a reasonable assumption…and god does it feel good to feel superior to another human being (engineers really love this, I don’t know why, it’s in the DNA though). It’s not a difficult mistake to make, but it starts to explain, at least in a metaphorical way (which is how we humans tend to make meaning), how my view of these things can be so different than the people I find myself around.

Metaphors aside, to me, what does it mean to be a senior software engineer? What is it that sets those people apart from their junior bretheren? First of all, it’s not technical knowledge. Or more specifically, not strictly a matter of memorized technical knowledge or ability. For me, it’s a matter of breadth of awareness, and the flexibility to be able to be effective in any area, any environment, any situation, any company, any codebase, any language, any product…in short, any job. It’s the ability to do whatever needs to be done, be that writing code, testing code, designing product specs, setting up servers, maintaining client relationships, balancing work and life, presenting oneself appropriately, acting appropriately…whatever it is, I expect a senior engineer to be able to adjust and manage through, while I would not expect a junior engineer to be able to handle the same wide variety of situations. I would not expect a senior engineer to know any specific language, but I would expect him to be able to program in any language or technology stack necessary to do whatever job needed to be done.

What I expect out of a junior engineer, is productive, technical competence in a small range of areas. This for instance, might be someone who can write solid C++ windows code, for shrink-wrap applications. It could be someone who knows Oracle databases inside and out, someone who is a browser UI wizard, guru, ninja, or whatever other absurd noun your marketing people would like to apply to us next, or it could be a server engineer, who can spin out PHP or Ruby code for days on end with no sustenance except Jolt cola and a 5 pound bag of gummy bears.

I expect almost complete technical competence out of a junior engineer…and I think this is where I get mixed up with people. I believe that my description of a junior engineer, is what most people would label as a senior engineer. And my description of a senior engineer, is what most people…don’t know what to do with. They certainly don’t call them senior engineers. They seem to have 2 alternatives, from what I’ve observed of those around me: 1) become an entrepreneur, and start your own company, 2) ignore much of what you know and can do, and do the menial, repetitive job of being a feature developer…because that is what is available most of the time. Occasionally, there is a position for a real, senior engineer in an existing company…but it’s increidibly rare. Most of the time, if you take a job with a company, no matter what the title, you are going to be a feature developer. That’s just what needs to be done most of the time. And to be honest, coming from someone who’s done it for years, good god it gets boring after a while.

I remember exactly the date, or really range of dates, when I became a senior engineer by my own standards. I had held the title for some number of years previous to that, but it was just a misplaced title, as most of them are. It was 2006. That year, I worked on close to a dozen different technology stacks, from top to bottom, OS to language to framework to APIs to machines. I was pushed, hard, from my comfort zone, by the necessity of a project with a very small number of people with a large vision in a big company, where it is very difficult to make waves and stand out. I went from being someone who was incredibly talented and competent at writing C++ application code, to someone who could write any kind of code, in any environment, any language. It all became the same. There was something very zen-like about it. All of the differences just started to melt away, when I realized that all programming jobs were essentially the same. You get a language, a device, a language, a framework, and an API, or some number of each of the above, and you write the same 6-10 types of code blocks.

There are quite a lot of counter-arguments, many of them very valid, but I’m not here to write a philosophy paper and defend my thesis. I did enough of that back in the day (god bless the Philosophy department at Cal Poly for putting up with me, may they reset in peace), what I hope you might take away from this…is to ask yourself, what does it mean to me to be a Senior Software Engineer, and how can I make sure I don’t make the mistake of pursuing the wrong career goals, or misinterpreting someone else’s behavior. Maybe you will pause for a moment and question your own ideas, to see if they stand up to even your own probing. Maybe I’m way off target for you…but maybe, I’m dead on, and I’ve hit on something that you knew all along, but couldn’t quite articulate.

One way or another, I hope I made you think.

Thanks
R.

Permalink 3 Comments