Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

fix for issue #227 #243

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions MKStoreKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@

#endif

#ifdef __OBJC__
#if ! __has_feature(objc_arc)
#error MKStoreKit is ARC only. Either turn on ARC for the project or use -fobjc-arc flag
#endif
#endif
/*!
* @abstract This notification is posted when MKStoreKit completes initialization sequence
*/
Expand Down
33 changes: 24 additions & 9 deletions MKStoreKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

#import "MKStoreKit.h"

@import StoreKit;
#import <StoreKit/StoreKit.h>
NSString *const kMKStoreKitProductsAvailableNotification = @"com.mugunthkumar.mkstorekit.productsavailable";
NSString *const kMKStoreKitProductPurchasedNotification = @"com.mugunthkumar.mkstorekit.productspurchased";
NSString *const kMKStoreKitProductPurchaseFailedNotification = @"com.mugunthkumar.mkstorekit.productspurchasefailed";
Expand Down Expand Up @@ -233,9 +233,9 @@ - (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue

- (void)initiatePaymentRequestForProductWithIdentifier:(NSString *)productId {
if (!self.availableProducts) {
// TODO: FIX ME
// Initializer might be running or internet might not be available
NSLog(@"No products are available. Did you initialize MKStoreKit by calling [[MKStoreKit sharedKit] startProductRequest]?");
UIAlertView *a = [[UIAlertView alloc] initWithTitle:@"Error contacting itunes store" message:@"Are you connected to the internet?" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil, nil];
[a show];
}

if (![SKPaymentQueue canMakePayments]) {
Expand Down Expand Up @@ -327,19 +327,34 @@ - (void)startValidatingAppStoreReceiptWithCompletionHandler:(void (^)(NSArray *r
if (!error) {
NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
NSInteger status = [jsonResponse[@"status"] integerValue];
NSString *originalAppVersion = jsonResponse[@"receipt"][@"original_application_version"];
[self.purchaseRecord setObject:originalAppVersion forKey:kOriginalAppVersionKey];
[self savePurchaseRecord];
if (jsonResponse[@"receipt"] != [NSNull null]) {
NSString *originalAppVersion = jsonResponse[@"receipt"][@"original_application_version"];
if (nil != originalAppVersion) {
[self.purchaseRecord setObject:originalAppVersion forKey:kOriginalAppVersionKey];
[self savePurchaseRecord];
}
else {
completionHandler(nil, nil);
}
}
else {
completionHandler(nil, nil);
}

if (status != 0) {
NSError *error = [NSError errorWithDomain:@"com.mugunthkumar.mkstorekit" code:status
userInfo:@{NSLocalizedDescriptionKey : errorDictionary[@(status)]}];
completionHandler(nil, error);
} else {
NSMutableArray *receipts = [jsonResponse[@"latest_receipt_info"] mutableCopy];
NSArray *inAppReceipts = jsonResponse[@"receipt"][@"in_app"];
[receipts addObjectsFromArray:inAppReceipts];
completionHandler(receipts, nil);
if (jsonResponse[@"receipt"] != [NSNull null]) {
NSArray *inAppReceipts = jsonResponse[@"receipt"][@"in_app"];
[receipts addObjectsFromArray:inAppReceipts];
completionHandler(receipts, nil);
}
else {
completionHandler(nil, nil);
}
}
} else {
completionHandler(nil, error);
Expand Down