0

I am implementing in-app purchased for my app. As such, I am using the product identifier format of com.companyname.product.feature. The product identifier is used for the in-app purchase (which is working fine in sandbox) and as a user default to know that the product has been purchased. When the user purchases a product, the com.companyname.product.feature user default is set to true. All is working except for the following.

One of my view controller's is listening for the user default change so that it can modify its behavior based on the product purchase. However the controller is never notified of the user default change. I have implemented this type of observation many times in the past, but this is not working. Can it have something to do with the "." in the key path (that I have never before done)?

In my app delegate:

NSString *const PHKeyIAPFeature = @"com.companyname.appname.feature";  // also the product ID for the features

In my observer:

  [[NSUserDefaults standardUserDefaults] addObserver:self forKeyPath:PHKeyIAPFeature options:NSKeyValueObservingOptionNew context:NULL];

In my IAP manager:

  [[NSUserDefaults standardUserDefaults] setBool:TRUE forKey:productIdentifier];

where productIdentifier = PHKeyIAPFeature.

I know that the user default is being updated when the product is purchased, as a restart of the app reflects the updated user default.

Any ideas? TIA for the help.

--John

johnnyspo
  • 619
  • 3
  • 7
  • 18
  • forKeyPath is only work for NSString, did you mean `forKeyPath:@"com.companyname.product.feature"` ? – Mil0R3 Sep 10 '12 at 00:59
  • Yes. I updated my problem description. – johnnyspo Sep 10 '12 at 02:13
  • The '.' will not make a difference as they are just part of the string. All I can suggest is that you use NSLog to print out `productIdentifier` to make absolutely sure it is the same as `PHKeyIAPFeature `. – Ander Sep 10 '12 at 02:20
  • Compared productIdentifier to PHKeyIAPFeature - they're the same. As a test, I changed a the key for a known-functioning user default; I added ".test" to the key string. Previously functioning observers are no longer receiving the notification!!! When I remove the ".test" from the key, everything functions as normal. I think there **IS** something with the period in the key string. Or am I missing something???? – johnnyspo Sep 10 '12 at 23:29

0 Answers0