Problems with iPad 3 and NSUserDefaults

I have had several apps that are approved and available on iTunes. I tested them on an iPad 2 running iOS 5.0. These are some of the 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 is successful and I unblock it by setting the NSUserDefaults variable.

Recently, some of my iPad 3 users have complained that they are buying a feature and it is still unlocked. I don't own an iPad 3, so I tested the released code on an iPad 2 and it works great.

Has anyone else experienced the same issue with iPad 3? Is there a bug or issue 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 it like

     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
}

      

+3


source to share


1 answer


I don't see the point of synchronization, but the NSUserDefaults alternative is better:

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

      



I'm not sure if the issue is related to the default NSUser settings, as I'm not lucky enough to have an iPad 3.

It is a good idea to NOT store the purchase data in the application in NSUserDefaults, as you can simply modify the plist file to look like you bought it ...

-2


source







All Articles