Permalink
Browse files

Tons of fixes:

 - Added an environment variable for setting the current storefront.
 - Produce a response after a delay, rather than immediately. This mimics the actual buy sequence more closely.
 - Documented the environment variables and the format of the products property list file.
 - The payment queue asserts that you can make payments before enqueuing a payment.
 - Fixed a NSNumberFormatter leak.
  • Loading branch information...
1 parent eb948cf commit 5166f35e81a66ea34142c952b72b5a28f9ce4ddc @millenomi committed Feb 13, 2010
Showing with 48 additions and 6 deletions.
  1. +23 −0 ILSimSKPaymentQueue.h
  2. +5 −2 ILSimSKPaymentQueue.m
  3. +7 −1 ILSimSKProductsRequest.m
  4. +12 −2 ILSimSKTiers.m
  5. +1 −1 SimStoreKit.xcodeproj/project.pbxproj
View
@@ -10,6 +10,29 @@
#import "ILSimSKPayment.h"
#import "ILSimSKPaymentTransaction.h"
+// ENVIRONMENT VARIABLES THAT CHANGE THIS CLASS'S BEHAVIOR:
+
+// if -boolValue == NO, the user cannot make payments.
+// Defaults to YES if missing.
+#define kILSimSKCanMakePaymentsEnvironmentVariable @"ILSimSKCanMakePayments"
+
+// the path to a plist file containing simulated store product info info.
+// format:
+// dict {
+// any number of @"<product code>" => dict {
+// @"Title" => @"<product title>";
+// @"Description" => @"<guess>";
+// @"Tier" => int(<a price tier, eg 1 for $0.99. 0 (free) is not a valid tier in IAP>);
+// @"ProductType" => int(<0 means nonconsumable, 1 consumable, 2 subscription>);
+// }
+// }
+#define kILSimSKProductsPlistEnvironmentVariable @"ILSimSKProductsPlist"
+
+// the storefront to use.
+// Use a currency symbol for the storefront -- f. ex. "USD" is the USA storefront, "EUR" an Euro-using storefront etc.
+// Default is USD.
+#define kILSimSKStorefrontCodeEnvironmentVariable @"ILSimSKStorefrontCode"
+
@protocol ILSimSKPaymentTransactionObserver;
View
@@ -35,7 +35,8 @@ @implementation ILSimSKPaymentQueue
+ (BOOL) canMakePayments;
{
- return [[[[NSProcessInfo processInfo] environment] objectForKey:@"ILSimSKCanMakePayments"] boolValue];
+ id o = [[[NSProcessInfo processInfo] environment] objectForKey:kILSimSKCanMakePaymentsEnvironmentVariable];
+ return !o || [o boolValue];
}
- (id) init
@@ -69,6 +70,8 @@ + (ILSimSKPaymentQueue*) defaultQueue;
- (void) addPayment:(ILSimSKPayment*) p;
{
+ NSAssert([ILSimSKPaymentQueue canMakePayments], @"Payments must be available to add payments onto the queue.");
+
ILSimSKPaymentTransaction* t = [[ILSimSKPaymentTransaction new] autorelease];
t.transactionState = kILSimSKPaymentTransactionStatePurchasing;
t.payment = p;
@@ -118,7 +121,7 @@ - (void) ask;
UIAlertView* a = [[UIAlertView new] autorelease];
a.delegate = self;
- NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init];
+ NSNumberFormatter* numberFormatter = [[NSNumberFormatter new] autorelease];
[numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[numberFormatter setLocale:p.priceLocale];
View
@@ -9,6 +9,7 @@
#import "ILSimSKProductsRequest.h"
#import "ILSimSKProduct_Private.h"
#import "ILSimSKTiers.h"
+#import "ILSimSKPaymentQueue.h"
@interface ILSimSKProductsRequest ()
@@ -53,6 +54,11 @@ - (void) start;
ILSimSKProductsResponse* r = [[[ILSimSKProductsResponse alloc] initWithProducts:prods invalidProductIdentifiers:badIDs] autorelease];
+ [self performSelector:@selector(produceResponse:) withObject:r afterDelay:2.0];
+}
+
+- (void) produceResponse:(ILSimSKProductsResponse*) r;
+{
[self.delegate productsRequest:self didReceiveResponse:r];
if (!cancelled && [self.delegate respondsToSelector:@selector(requestDidFinish:)])
[self.delegate requestDidFinish:self];
@@ -65,7 +71,7 @@ - (void) cancel;
+ (ILSimSKProduct*) simulatedProductForIdentifier:(NSString*) ident;
{
- NSString* productsFile = [[[NSProcessInfo processInfo] environment] objectForKey:@"ILSimSKProductsPlist"];
+ NSString* productsFile = [[[NSProcessInfo processInfo] environment] objectForKey:kILSimSKProductsPlistEnvironmentVariable];
NSDictionary* d = productsFile? [NSDictionary dictionaryWithContentsOfFile:productsFile] : nil;
NSDictionary* productData = [d objectForKey:ident];
View
@@ -7,6 +7,7 @@
//
#import "ILSimSKTiers.h"
+#import "ILSimSKPaymentQueue.h"
NSString* const kILSimStorefront_USD = @"USD";
NSString* const kILSimStorefront_EUR = @"EUR";
@@ -15,9 +16,18 @@
static NSString* storefront = nil;
+static BOOL ILSimSKIsKnownStorefront(NSString* sf) {
+ return [sf isEqual:kILSimStorefront_USD] || [sf isEqual:kILSimStorefront_CAD] ||
+ [ILSimSKAllTierPricesByStorefront() objectForKey:sf] != nil;
+}
+
NSString* ILSimSKCurrentStorefront() {
- if (!storefront)
- ILSimSKSetCurrentStorefront(kILSimStorefront_USD);
+ if (!storefront) {
+ NSString* e = [[[NSProcessInfo processInfo] environment] objectForKey:kILSimSKStorefrontCodeEnvironmentVariable];
+ if (!e || !ILSimSKIsKnownStorefront(e))
+ e = kILSimStorefront_USD;
+ ILSimSKSetCurrentStorefront(e);
+ }
return storefront;
}
@@ -38,7 +38,7 @@
isa = PBXContainerItemProxy;
containerPortal = 0867D690FE84028FC02AAC07 /* Project object */;
proxyType = 1;
- remoteGlobalIDString = D2AAC07D0554694100DB518D /* SimStoreKit */;
+ remoteGlobalIDString = D2AAC07D0554694100DB518D;
remoteInfo = SimStoreKit;
};
/* End PBXContainerItemProxy section */

0 comments on commit 5166f35

Please sign in to comment.