When Users Try To Upgrade An App Without a Connection

Store Kit is a great API because it lets developers create one app that can be enhanced through upgrades, buying tools, or whatever feature we want to offer the user to make the application more useful. In my case, all I want users to be able to do is upgrade their copy of Flush ’em! from the free edition for 99¢. The Flush ’em! upgrade allows the user to select from three bathroom choices.

But, there will come a time when a user will try to upgrade an app when she/he doesn’t have a network connection. And it’s fairly certain that such a user will flame the app page if the app doesn’t give the user the ability to go to Settings, turn on the network capability and then continue back to where the user left-off in the app to upgrade.

 

The way I initially designed Flush ’em! was to call -requestProductData and then -productsRequest:didRecieveResponse: in the AppDelegate’s -application:didFinishLaunchingWithOptions: method. For a problem such as the one described above, that design is borked.

One of the neat things about iOS4 is the multitasking capabilities. And that offers a way out of this hole. One solution is to restart the product request call in the Flush ’em! FlushViewController where I’m handling monitoring when the app goes into the background. Such as,


- (void)awakeFromNib
{
[super awakeFromNib];

//
// These methods are to handle the Flush'em! when it enters the background. Entering the background
// stops the flush button animation by default but leaves the button background color to red. I want
// that to be done in a bit more of a slick manner.
//
// If the flush button is enabled then pulse the button, else set the background to clearColor and stop the button animation.
//
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];

// Register for notification that app did enter background
[notificationCenter addObserver:self selector:@selector(leaveFlushem) name:UIApplicationDidEnterBackgroundNotification object:nil];

// Register for notification that app did enter foreground
[notificationCenter addObserver:self selector:@selector(resumeFlushem) name:UIApplicationWillEnterForegroundNotification object:nil]
}

– (void)resumeFlushem
{
if (self.flushButton.enabled)
{
[self animateFlushButton];
}
else {
self.flushButton.backgroundColor = [UIColor clearColor];
}

 

[[PFIAPManager sharedManager] requestProductData];
}

And in the Flush ’em! SettingsViewController, where the user actually upgrades Flush ’em!, I do the same basic thing,


- (void)awakeFromNib
{
[super awakeFromNib];

NSLog(@"-awakeFromNib\n\n\n");

//
// These methods are to handle the Flush’em! when it enters the background. Entering the background
// stops the flush button animation by default but leaves the button background color to red. I want
// that to be done in a bit more of a slick manner.
//
// If the flush button is enabled then pulse the button, else set the background to clearColor and stop the button animation.
//
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];

// Register for notification that app did enter foreground
[notificationCenter addObserver:self selector:@selector(resumeFlushem) name:UIApplicationWillEnterForegroundNotification object:nil];

NSLog(@”-awakeFromNib finished”);
}

 

- (void)resumeFlushem
{
[[PFIAPManager sharedManager] requestProductData];
}

In this way, no matter where the user is, after the network settings reestablish a connection and the user returns to Flush ’em!, the user can upgrade to Flush ’em! Pro.

Advertisements