3

I have had a couple of apps that are approved and available in iTunes. I tested them on an iPad 2 with iOS 5.0. They are some features that are unlocked through in-app purchases in those apps. Once the user successfully buys a certain feature, I check to make sure the transaction was successful and i unlock it by setting a NSUserDefaults variable.

Recently some of my iPad 3 users have been complaining that they buy a feature and it is still unlocked. I don't own iPad 3 so I tested the released code on iPad 2 and it works just fine.

Has anyone else experienced the same issue with iPad 3? Is there some bug or problem with NSUserDefaults in iOS 5.1?

Here is the code

NSArray *stringsArray2a = [[NSArray alloc] initWithObjects: @"1", nil];
        [[NSUserDefaults standardUserDefaults] setObject:stringsArray2a forKey:@"MyAppWeatherPackStr"];
        [[NSUserDefaults standardUserDefaults] synchronize];

Then I check for it like this

     NSArray *purchasedAppArray = [[NSUserDefaults standardUserDefaults] objectForKey:@"MyAppWeatherPackStr"];
        NSString *purchasedAppStr = [purchasedAppArray objectAtIndex:0];

if([purchasedAppStr isEqualToString:@"1"])
    {
        //all good keep checking weather

    }
    else
{
//can't check weather
}
Sam B
  • 27,273
  • 15
  • 84
  • 121
  • What does your code look like? – Paul.s Apr 07 '12 at 01:52
  • Does the array ever contain more than one string? – Paul.s Apr 07 '12 at 02:10
  • no, it always contains one string. Here's a thing, the code is not the problem here. If it was I won't be able to successfully test in on iPAD 2 running iOS 5.0. So it gotta be something in iOS 5.1? Though I don't know. If there was a problem there would have been an uproar by now. – Sam B Apr 07 '12 at 02:12
  • Are you sure customers on iPad 2 have purchased the component? – Paul.s Apr 07 '12 at 02:24
  • I would recommend to check the code that actually calls the 3 lines that save to NSUserDefaults. The NSUserDefaults code is probably not your problem, maybe the receipt validation is. – Matthias Bauch Apr 07 '12 at 09:37
  • Thanks Matt, will check again. Just wish I could afford to buy iPAD 3 to test it out. Simulator is great and all but its not like the real thing. – Sam B Apr 07 '12 at 17:51
  • Check [this answer](http://stackoverflow.com/questions/4978852/storing-in-app-purchase-receipts-in-the-application-keychain) for how to store that in the Keychain. – Eric Jun 07 '13 at 00:08

1 Answers1

-2

I don't see the point of syncing but a better alternative NSUserDefaults is:

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:forKey stringsArray2a:@"1"];

I'm not sure were the problem is with NSUser defaults as I'm not fortunate enough to have an iPad 3.

A good idea is to NOT store in-app purchase data in NSUserDefaults as you can just mod the plist file to look like you bought it...

Allison
  • 2,213
  • 4
  • 32
  • 56
  • How can you just modify the plist? – Paul.s Apr 07 '12 at 02:27
  • What does that code actually do? Where is the method `setObject:stringsArray2a:` coming from? – Paul.s Apr 07 '12 at 02:28
  • Jailbroken phoned can simply modify the user defaults plist since it is stored in plaintext. – borrrden Apr 07 '12 at 02:56
  • @borrrden If the user has Jailbroken their phone the likelihood is they are the type of customer who is not going to pay anyway - therefore they are not your customers – Paul.s Apr 07 '12 at 02:58
  • That is a bit of a bold statement, jailbreaking does not make you a bad person, but I will not flood your question with an ethical debate. I just wanted to point out a technical way. – borrrden Apr 07 '12 at 03:07
  • Paul.s is saying that if a user is willing to change a plist to not pay for an in-app purchase, not using that plist isn't going to stop them from getting the app extras without paying anyway. – Scott Berrevoets Apr 07 '12 at 06:19
  • The point of syncing is to commit the changes to the PList right then. This is a good habit to get into, as those changes are not committed right away. – LJ Wilson Apr 07 '12 at 11:54
  • Any ways for the topic using an SQL database will fend off any non experts. Also using MySql would fix your NSUserDefaults problem. – Allison Apr 07 '12 at 14:50
  • Wow, this topic went way off fast. – Sam B Apr 07 '12 at 17:50