From c7f577e0761d9c0f4f337bdb7dc55e5d2533305b Mon Sep 17 00:00:00 2001 From: David H Date: Thu, 8 Dec 2011 14:42:23 -0800 Subject: [PATCH] Fix IAP for iOS: apply()'s "this" argument needs to be set. When I changed the JS callbacks to use `apply()`, I left the "this" argument set to null. This caused code in InAppPurchaseManager.prototype.updatedTransactionCallback to fail because references to `this` become null instead of references to the default instance of InAppPurchaseManager. This commit modifies the apply() calls to use plugins.inAppPurchaseManager as the "this" argument. --- iPhone/InAppPurchaseManager/InAppPurchaseManager.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iPhone/InAppPurchaseManager/InAppPurchaseManager.m b/iPhone/InAppPurchaseManager/InAppPurchaseManager.m index 305195f..79efd12 100644 --- a/iPhone/InAppPurchaseManager/InAppPurchaseManager.m +++ b/iPhone/InAppPurchaseManager/InAppPurchaseManager.m @@ -153,7 +153,7 @@ NILABLE(productId), NILABLE(transactionReceipt), nil]; - NSString *js = [NSString stringWithFormat:@"plugins.inAppPurchaseManager.updatedTransactionCallback.apply(null, %@)", [callbackArgs JSONSerialize]]; + NSString *js = [NSString stringWithFormat:@"plugins.inAppPurchaseManager.updatedTransactionCallback.apply(plugins.inAppPurchaseManager, %@)", [callbackArgs JSONSerialize]]; NSLog(@"js: %@", js); [self writeJavascript: js]; [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; @@ -191,7 +191,7 @@ NILABLE(product.localizedDescription), NILABLE(product.localizedPrice), nil]; - NSString *js = [NSString stringWithFormat:@"%@.apply(null, %@)", successCallback, [callbackArgs JSONSerialize]]; + NSString *js = [NSString stringWithFormat:@"%@.apply(plugins.inAppPurchaseManager, %@)", successCallback, [callbackArgs JSONSerialize]]; NSLog(@"js: %@", js); [command writeJavascript: js]; } @@ -245,7 +245,7 @@ NILABLE(validProducts), NILABLE(response.invalidProductIdentifiers), nil]; - NSString *js = [NSString stringWithFormat:@"%@.apply(null, %@);", callback, [callbackArgs JSONSerialize]]; + NSString *js = [NSString stringWithFormat:@"%@.apply(plugins.inAppPurchaseManager, %@);", callback, [callbackArgs JSONSerialize]]; [command writeJavascript: js]; [request release];