Permalink
Browse files

Fixed tons of gotchas.

  • Loading branch information...
1 parent 6cbedf9 commit 98fa4bb1d2e48d9fcec3492bd9d8d96049edb0ed @millenomi committed Feb 3, 2010
Showing with 27 additions and 4 deletions.
  1. +12 −2 ILSimSKPaymentQueue.m
  2. +6 −0 ILSimStoreKit.h
  3. +9 −2 TestApp.m
View
@@ -140,6 +140,7 @@ - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)butto
break;
case 1:
[self fail:[NSError errorWithDomain:kILSimSKErrorDomain code:kILSimSimulatedFailure userInfo:nil]];
+ break;
case 2:
default:
[self fail:[NSError errorWithDomain:NSCocoaErrorDomain code:NSUserCancelledError userInfo:nil]];
@@ -176,12 +177,17 @@ - (void) succeed;
self.currentTransaction.transactionState = kILSimSKPaymentTransactionStatePurchased;
NSMutableArray* a = [[[[NSUserDefaults standardUserDefaults] arrayForKey:@"ILSimSKTransactions"] mutableCopy] autorelease];
- if (!d)
+ if (!a)
a = [NSMutableArray array];
[a addObject:r];
[[NSUserDefaults standardUserDefaults] setObject:a forKey:@"ILSimSKTransactions"];
+ [self performSelector:@selector(signalFinished) withObject:nil afterDelay:2.0];
+}
+
+- (void) signalFinished;
+{
for (id <ILSimSKPaymentTransactionObserver> o in observers)
[o paymentQueue:self updatedTransactions:[NSArray arrayWithObject:self.currentTransaction]];
}
@@ -190,14 +196,18 @@ - (void) fail:(NSError*) e;
{
self.currentTransaction.error = e;
self.currentTransaction.transactionState = kILSimSKPaymentTransactionStateFailed;
+ NSArray* t = [NSArray arrayWithObject:self.currentTransaction];
+
for (id <ILSimSKPaymentTransactionObserver> o in observers)
- [o paymentQueue:self updatedTransactions:[NSArray arrayWithObject:self.currentTransaction]];
+ [o paymentQueue:self updatedTransactions:t];
}
- (void) finishTransaction:(ILSimSKPaymentTransaction*) t;
{
if ([transactions count] > 0 && self.currentTransaction == [transactions objectAtIndex:0])
[transactions removeObjectAtIndex:0];
+ else
+ return;
for (id <ILSimSKPaymentTransactionObserver> o in observers) {
if ([o respondsToSelector:@selector(paymentQueue:removedTransactions:)])
View
@@ -18,5 +18,11 @@
#define SKProductsRequestDelegate ILSimSKProductsRequestDelegate
#define SKPaymentTransactionObserver ILSimSKPaymentTransactionObserver
#define SKRequestDelegate ILSimSKRequestDelegate
+#define SKProductsResponse ILSimSKProductsResponse
+
+#define SKPaymentTransactionStatePurchased kILSimSKPaymentTransactionStatePurchased
+#define SKPaymentTransactionStateFailed kILSimSKPaymentTransactionStateFailed
+#define SKPaymentTransactionStatePurchasing kILSimSKPaymentTransactionStatePurchasing
+#define SKPaymentTransactionStateRestored kILSimSKPaymentTransactionStateRestored
#endif
View
@@ -28,7 +28,7 @@ - (IBAction) buy;
[pr start];
}
-- (void) productsRequest:(ILSimSKProductsRequest *)request didReceiveResponse:(ILSimSKProductsResponse *)response;
+- (void) productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response;
{
if ([response.products count] == 0)
return;
@@ -38,9 +38,16 @@ - (void) productsRequest:(ILSimSKProductsRequest *)request didReceiveResponse:(I
[[SKPaymentQueue defaultQueue] addPayment:pay];
}
-- (void) paymentQueue:(ILSimSKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions;
+- (void) paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions;
{
NSLog(@"%@", transactions);
+
+ for (SKPaymentTransaction* t in transactions) {
+ if (t.transactionState == SKPaymentTransactionStatePurchased || t.transactionState == SKPaymentTransactionStateFailed) {
+ NSLog(@"%@ -> state %d", t, t.transactionState);
+ [queue finishTransaction:t];
+ }
+ }
}
@end

0 comments on commit 98fa4bb

Please sign in to comment.