This occurs because even though your target deployment OS is 3.1.2, the base SDK that you're using is probably 4.0 or 4.1, and thus __IPHONE_3_2 is defined. To target older devices (OS less than 3.2) while using a newer SDK like the one you're using, you'll have to modify the code:
#ifdef __IPHONE_3_2
CGSize keyboardSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
#else
CGSize keyboardSize = [[userInfo objectForKey:UIKeyboardBoundsUserInfoKey] CGRectValue].size;
#endif
To the following code:
CGSize keyboardSize = [[userInfo objectForKey:UIKeyboardBoundsUserInfoKey] CGRectValue].size;
Note: we could check the system version using [[UIDevice currentDevice] systemVersion] and do this call automatically, but including the code [userInfo objectForKey:UIKeyboardBoundsUserInfoKey] will have STV's code generate a compiler warning "UIKeyboardBoundsUserInfoKey is deprecated". Since the vast majority of our users are not deploying on 3.1.x devices, we do not wish to flood their screen with compiler warnings at build time.