The problem was that, after I had submitted my app, I ran into the in-app-purchase limitation on my own device. To get around this, I commented out the check for purchase code in my app. Then I got busy with life and completely forgot about it. So, when I went to make an enhancement to the app, I was happily coding away when I quite accidentally got into the same section of code which checks for the purchase. I was completely taken aback when I saw the code completely skipping the check for the app purchase. Would Apple have caught the problem had I submitted it? I doubt it - they wouldn't go up to 100. Once released, there would be no reason to purchase the app - I would have been giving out the whole thing for free. With a 1% fill rate for the iAd advertising, I'm not going to be making money on ads, that's for sure. Who knows when I would have finally realized I was giving it away? Note to self - don't *do* stuff like that.
So, as soon as I got over my shock, I immediately set about fixing up the problem. The solution clearly lends itself to some type of checking of the unique id of the device. Surprisingly, this turned out to be very easy to code - just one line, and no permissions required. It can be retrieved and logged as follows:
NSString * uniqueId = [[UIDevice currentDevice] uniqueIdentifier];
NSLog(@"uniqueIdentifier: %@", uniqueId);
There is one important caveat - this method has been deprecated in iOS 5. However, until some future date, it's going to be my solution. Once that method is gone, my app won't compile - there's no danger of giving it away for free.
This method works on the simulators too. It turns out that they all have the same id (amongst themselves, not the iPod Touch). With that information in hand, I quickly created this code:
+ (BOOL) isFreeVersion {
NSString *productIdentifer = @"com.mycompany.myapp.myinapppurchase";
if
(
([uniqueId isEqualToString:@"xxxyyyzzz"]) || // my device's id
([uniqueId isEqualToString:@"zzzyyyxxx"]) // my simulator's id
)
{
return NO; // it's been purchased
}
BOOL productPurchased = [[NSUserDefaults standardUserDefaults] boolForKey:productIdentifer];
return !productPurchased;
}
Nice and quick. Let's hope Apple doesn't get around to deprecating this one for a while.
No comments:
Post a Comment