Posts tagged ‘iPhone SDK’

Two more iPhone SDK facts you may not know

Here are two other fun facts I discovered about the iPhone SDK:

1. You can present a modal view controller on top of another modal view controller

This would appear to contradict fact #2 from my posting of July 13th, but I have learned some new information. In my previous attempts to stack up modal view controllers, I was sending the presentModalViewController method call to the navigation controller defined in my app delegate. For the second modal view controller, if I just send the presentModalViewController method call in the first view controller to self, all works as it should.

2. Watch your colons on delegate selectors

I was trying to wire up a cancel delegate call that passed no parameters back to the caller, since none are necessary. However, the cancel delegate that I copied and changed from the working accept delegate was never firing in the following code:

if (delegate && [delegate respondsToSelector:@selector(myDelegateCancelPressed:)]) {
    [delegate myDelegateCancelPressed];
}

After I removed the colon from inside the @selector, it worked right as rain.

Two iPhone SDK facts you may not know

I discovered (quite by accident) two things today about iPhone software development. These are things that are probably documented and discussed elsewhere, so here is yet another documenting/mentioning of them.

1. The order of stuff in Interface Builder is actually pretty important

So I am in Interface Builder, copying and pasting some repetitive stuff. I usually like to have the document window open on the left of the screen, the view open middle left, the inspector middle right, and the library on the right. And every once in a while, the stuff I pasted that showed up at the bottom of the list of controls in my view disappeared.

As it turns out, this was happening when I was subconsciously sending the newly pasted controls to the back, and as you may not know, the order of the controls as shown in a view pertains exactly to the z-order of the controls. The control that I was sending to the back going to the top of the list of controls under the view in the document window.

2. Don’t try to present a modal view controller on top of another modal view controller

The subject above says it all. If you create a view controller and use the presentModalViewController method, nothing really happens. The new view is created, but just sort of fizzles out before reaching the screen. (Or in other words, the init is called, but viewDidLoad is never reached.)

This will present a bit of a challenge, as just about every other environment I have worked in allows you to lay modals on top of other modals.

Shine On You Crazy Icon

If you are trying to remove the shine effect from the icon on your iPhone application, and it is not working, check the order of items in your info.plist file.

I had the “Icon already includes gloss effects” item at the bottom of my plist file with a value of checked, but it would not get rid of the shiny icon on the simulator or on a device. I found that, after I moved the entry up to the top of the plist file, it now gave me an unshiny icon on the simulator and on a new device that I tried the software on.

My main iPod touch that I use for development still has the shiny icon even after deleting the application from the device and powering it off and back on. Anyone have any ideas why this would be?

iPhone app update available in App Store

Good news for those of you who tried to use the first revision of our Basketball Statware iPhone app and found yourself looking at a silently failing crash when you sync.

Version 1.0.1 of Basketball Statware is now available for download in the App Store. Also, a little bug was fixed up concerning visiting the event list view when you do not have any events in your game.

Here is the URL for the product:

Basketball Statware (link redacted, no longer available)

The next revision of the application is going to have more minor bug fixes and memory leak fixes, as well as a neat feature that switches between a box score summary and an extended box score summary by rotating the device from portrait to landscape mode. This is almost ready to be submitted to Apple for approval, and should be ready by the middle of July.

iPhone app accepted!

Good news!

Our iPhone app was accepted into the iTunes App Store on the very first try!!!

I am far too tired to post details right now, I will modify this message after I recover a bit. For now, if you want to see it, fire up your iTunes, go into the App Store, and search for Basketball Statware.

iPhone app submitted to App Store

A momentous occasion, my company’s first iPhone app has been submitted to the App Store. Hopefully it will fly through the review process within minutes and be accepted the very first time. OK, maybe not.

There was one application uploading issue I ran into. The distribution code built just fine after a bit of tweaking, but upon uploading the .zip file to the iTunes Connect page, I got the following error:

The binary you uploaded was invalid. The application-identifier entitlement is not formatted correctly;
it should contain your 10-character App ID Seed, followed by a dot, followed by your bundle identifier.

As it turns out, I needed to make some changes to my Entitlements.plist file that did not appear to be mentioned or documented anywhere. Thanks to the TwoAppGuys and their blog entry “iOS4 and the wildcard” (link removed as it was broken) for the solution to this issue.

I will post again when I learn the ultimate fate of our app.

iPhone code signing issues

So I am trying to get a project started a while back into a state where it can be submitted to the app store, and of course it never goes smoothly. Today’s issue was a bunch of build and code signing errors that occurred when I tried to switch from using an older iPhone developer account to our current one, and added a new development device to the provisioning profile.

Here were the steps that I took to finally get it building and running on my development devices:

  • Regenerate the development certificate and provisioning profile after adding the new development device
  • Move the development certificate from the system area into the login area in Keychain Access
  • Clean out the old provisioning profiles in the Xcode organizer and from the device
  • Add the new provisioning profile to the device
  • Add the new provisioning profile to the provisioning profile section of the Organizer under iPhone Development
  • Change the code signing identity in the Project info Build tab and in the Target info Build tab

Once I did all these steps, it started to build and run on the device. Now I just can’t wait until I try to build for distribution and submit to the App Store. What could possibly go wrong?

UIButton can sing and dance, too!

Apparently, there is no way to take a UIButton and set it’s property to “selected” for the purposes of having the UI display the button with the background image as it appears in the UIControlStateSelected state. As a result, I decided that I would just track which of my series of UIButton controls was supposed to be selected, set the background image of all the buttons to nil, and set the UIControlStateNormal background image of the button to an image, and it seemed to work OK.

The code to do this, however, was kind of ugly, and my co-worker on this project pushed me to find a better way. The result is the ExpandoButton class that we created and added to the project. For this class (which of course inherits UIButton), I wanted to be able to initialize it to a particular background image, and I wanted to have a message I could send the button to have it switch back and forth from the unselected background image to the selected background image.

Here are the header and implementation files for the ExpandoButton object class:

//
//  ExpandoButton.h
//
 
#import <Foundation/Foundation.h>
 
@interface ExpandoButton : UIButton {
 
}
 
- (void)setSelectedImage:(BOOL)isSelected;
 
@end
//
//  ExpandoButton.m
//
 
#import "ExpandoButton.h"
 
@implementation ExpandoButton
 
- (id)initWithCoder:(NSCoder *)decoder
{
	if (self = [super initWithCoder:decoder]) {
		UIImage *image = [UIImage imageNamed:@"button_normal.png"];
		UIImage *stretchImage =
					[image stretchableImageWithLeftCapWidth:4.0 topCapHeight:4.0];
		[self setBackgroundImage:stretchImage forState:UIControlStateNormal];
		self.backgroundColor = [UIColor clearColor];
	}
 
	return self;
}
 
- (void)setSelectedImage:(BOOL)isSelected
{
	NSString *file;
 
	if (isSelected)
	{
		file = @"button_selected.png";
	}
	else 
	{
		file = @"button_normal.png";
	}
 
	UIImage *image = [UIImage imageNamed:file];
	UIImage *stretchImage =
				[image stretchableImageWithLeftCapWidth:4.0 topCapHeight:4.0];
	[self setBackgroundImage:stretchImage forState:UIControlStateNormal];
}
 
@end

A few notes here about the implementation file. You will of course need to add the stretchable unselected and selected button images to your project and change the names above, along with changing the cap width and height to your needs. Also, the initWithCoder part took us a few moments to figure out, it wasn’t working at first because we weren’t calling the super’s initWithCoder, just the regular old init. And finally, keep in mind that there is no error checking, optimization, or memory leak checking going on here.

To actually use the ExpandoButton, go into your Interface Builder, and from the Library window, select the Classes option, make sure the choice list right below is set to Library, and you should then be able to scroll the list and see an ExpandoButton, which looks just like a UIButton. Put that object on your view and set the size and title if you wish. VERY IMPORTANT: Make sure to set the button type of your ExpandoButton to Custom instead of the default of Rounded Rect.

Then, in your view controller header file, set up an IBOutlet with type of ExpandoButton (don’t forget the header or @class), along with the corresponding @property, and in the view controller implementation file, set up the @synthesize. After you save the files and build, go back into Interface Builder and set up the connection between the IBOutlet and the ExpandoButton on the view. (I hope you remembered where it was. When you set it to Custom and if you do not have any title text, the button sort of disappears.)

If everything is hooked up and working correctly, in your implementation file code, you can do something like this:

[myExpandoButton setSelectedImage:YES];

And the button should show up with the selected background image.

iPad 101: A Magical and Revolutionary Introduction (CIDUG meeting, May 25, 2010)

Justin Munger gave a presentation on some of the new features of the iPad and how to utilize them in the iPhone SDK at the Columbus iPhone Developer User Group on May 25, 2010. The topics he covered were the new modal dialogs, split views, gesture recognizers, and building a universal application for both iPhone and iPad.

A pearl of great price

If you are using Xcode for either Macintosh or iPhone development, please go to one of your implementation files in Xcode right now, hold down Control and Command and press the up arrow. Your life will be much better.