0

I have implemented iAP in my application, I'm try to purchase but in StoreKitController controller its return previous transaction detail.

Example: First i purchased with product name "ABC", this transaction is completed, After that i try to another transaction with product "XYZ", but in 2nd transaction i'm getting product name and product price of product "ABC" in below method.

- (void)DoBuy:(NSString*)ProductName PaymentType:(int)type Quantity:(int)Q
{
    DLog(@"Product is.......%@",ProductName);
    // My code
}

Product is.......ABC

And

- (void) completeTransaction: (SKPaymentTransaction *)transaction
{
  DLog(@"Price is..%lf",ProductPrice);
  DLog(@"%@",transaction.payment.productIdentifier);
  // My Code
}

Price is...1.990000 ABC

But actually here it should be for product "XYZ" with price 2.99

Thanks in Advance.

Ashvin
  • 8,227
  • 3
  • 36
  • 53
  • I know this type of question ask but here my problem is just different. I dont know my array(NSMutableArray) and within array here dictionary(NSDictionary) is as an object. But whenever i'm take array from NSUserDefault Its automatically become Non-Mutable dictionary. – Ashvin Oct 04 '12 at 06:20
  • Your problem is exactly the same. You are getting a dictionary out of NSUserDefaults and calling setObject:forKey: on it. What about the answer to that question are you having trouble with? – Carl Veazey Oct 04 '12 at 06:25
  • I tried "mutablecopy" before i had post here my question not working. – Ashvin Oct 04 '12 at 06:36
  • 1
    Just because you mutableCopy your array doesn't mutableCopy the dictionary in it... EDIT: load this array: `[[NSUserDefaults standardUserDefaults] objectForKey:@"InvoiceArray"]` create a new array of mutable copies, add that to your `InvoiceInfoArray` – Carl Veazey Oct 04 '12 at 06:38
  • Ok Now array is become mutable still Dictionary is not mutable.. i test like NSMutableDictionary *temp = [AppDel.InvoiceInfoArr objectAtIndex:AppDel.SelectedRowForInvoice]; But here i'm getting temp is immutabledictionary. – Ashvin Oct 04 '12 at 07:24
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/17542/discussion-between-carl-veazey-and-bapu) – Carl Veazey Oct 04 '12 at 07:32

3 Answers3

0

If your InvoiceInfoArr is NSArray make it NSMutableArray.

parilogic
  • 1,147
  • 9
  • 26
  • Thanks for replay.. here array and dictionary both are Mutable.. I know this type of question ask but here my problem is just different. I dont know my array(NSMutableArray) and within array here dictionary(NSDictionary) is as an object. But whenever i'm take array from NSUserDefault Its automatically become Non-Mutable dictionary. – Ashvin Oct 04 '12 at 06:21
  • Does [AppDel.InvoiceInfoArr objectAtIndex:AppDel.SelectedRowForInvoice] returns dictionary? Just cross check. – parilogic Oct 04 '12 at 06:49
0

From NSUserDefaults you're getting array of NSDictionaries, which are immutable so you cannot change their content. You have to iterate over the array and change NSDictionaries to NSMutableDictionaries

Just try this

for (NSUInteger i = 0; i < AppDel.InvoiceInfoArr.count; i++) {
    NSDictionary *dict = [AppDel.InvoiceInfoArr objectAtIndex:i];
    NSMutableDictionary *mutableDict = [dict mutableCopy];
    [AppDel.InvoiceInfoArr replaceObjectAtIndex:i withObject:mutableDict];
}
xxcv
  • 331
  • 2
  • 11
  • Thanks for replay.. here array and dictionary both are Mutable.. I dont know my array(NSMutableArray) and within array here dictionary(NSDictionary) is as an object. But whenever i'm take array from NSUserDefault Its automatically become Non-Mutable dictionary. – Ashvin Oct 04 '12 at 06:22
  • You've got for sure immutable dictionaries in the array. Try the code I've added to the post – xxcv Oct 04 '12 at 08:48
0

you are trying to set object for an key in an NSDictionary which causes the crash , where as you need to typecast the dictionary to a mutable dictionary . Hope this helps.

Singh
  • 2,151
  • 3
  • 15
  • 30