Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for iOS: getProductsInfo crashes the app #70

Open
wants to merge 1 commit into
base: develop
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
8 changes: 0 additions & 8 deletions ios/AirInAppPurchase.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@
objects = {

/* Begin PBXBuildFile section */
5AC18A8B152A0AED007399DB /* JSONKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 5AC18A89152A0AED007399DB /* JSONKit.h */; };
5AC18A8C152A0AED007399DB /* JSONKit.m in Sources */ = {isa = PBXBuildFile; fileRef = 5AC18A8A152A0AED007399DB /* JSONKit.m */; };
BFA8AB071527AFB700845071 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BFA8AB061527AFB700845071 /* Foundation.framework */; };
BFA8AB0D1527AFB700845071 /* AirInAppPurchase.m in Sources */ = {isa = PBXBuildFile; fileRef = BFA8AB0C1527AFB700845071 /* AirInAppPurchase.m */; };
BFA8AB141527B02300845071 /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BFA8AB131527B02300845071 /* StoreKit.framework */; };
FA82D92D17B00A3500792905 /* FlashRuntimeExtensions.h in Headers */ = {isa = PBXBuildFile; fileRef = FA82D92C17B00A3500792905 /* FlashRuntimeExtensions.h */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
5AC18A89152A0AED007399DB /* JSONKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JSONKit.h; path = JSONKit/JSONKit.h; sourceTree = SOURCE_ROOT; };
5AC18A8A152A0AED007399DB /* JSONKit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = JSONKit.m; path = JSONKit/JSONKit.m; sourceTree = SOURCE_ROOT; };
BFA8AB031527AFB700845071 /* libAirInAppPurchase.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libAirInAppPurchase.a; sourceTree = BUILT_PRODUCTS_DIR; };
BFA8AB061527AFB700845071 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
BFA8AB0A1527AFB700845071 /* AirInAppPurchase-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "AirInAppPurchase-Prefix.pch"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -69,8 +65,6 @@
BFA8AB081527AFB700845071 /* AirInAppPurchase */ = {
isa = PBXGroup;
children = (
5AC18A89152A0AED007399DB /* JSONKit.h */,
5AC18A8A152A0AED007399DB /* JSONKit.m */,
BFA8AB0B1527AFB700845071 /* AirInAppPurchase.h */,
BFA8AB0C1527AFB700845071 /* AirInAppPurchase.m */,
BFA8AB091527AFB700845071 /* Supporting Files */,
Expand All @@ -94,7 +88,6 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
5AC18A8B152A0AED007399DB /* JSONKit.h in Headers */,
FA82D92D17B00A3500792905 /* FlashRuntimeExtensions.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -150,7 +143,6 @@
buildActionMask = 2147483647;
files = (
BFA8AB0D1527AFB700845071 /* AirInAppPurchase.m in Sources */,
5AC18A8C152A0AED007399DB /* JSONKit.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
1 change: 0 additions & 1 deletion ios/AirInAppPurchase/AirInAppPurchase.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#import <Foundation/Foundation.h>
#import <StoreKit/StoreKit.h>
#import "FlashRuntimeExtensions.h"
#import "JSONKit.h"

@interface AirInAppPurchase : NSObject <SKPaymentTransactionObserver, SKProductsRequestDelegate>

Expand Down
30 changes: 22 additions & 8 deletions ios/AirInAppPurchase/AirInAppPurchase.m
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,18 @@ - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProdu
[dictionary setObject:productElement forKey:@"details"];


NSString* jsonDictionary = [dictionary JSONString];
NSError * err;
NSData * productInfoData = [NSJSONSerialization dataWithJSONObject:dictionary options:0 error:&err];
NSString * productInfoString = [[NSString alloc] initWithData:productInfoData encoding:NSUTF8StringEncoding];

FREDispatchStatusEventAsync(AirInAppCtx ,(uint8_t*) "PRODUCT_INFO_RECEIVED", (uint8_t*) [jsonDictionary UTF8String] );
FREDispatchStatusEventAsync(AirInAppCtx ,(uint8_t*) "PRODUCT_INFO_RECEIVED", (uint8_t*) [productInfoString UTF8String]);

if ([response invalidProductIdentifiers] != nil && [[response invalidProductIdentifiers] count] > 0)
{
NSString* jsonArray = [[response invalidProductIdentifiers] JSONString];

FREDispatchStatusEventAsync(AirInAppCtx ,(uint8_t*) "PRODUCT_INFO_ERROR", (uint8_t*) [jsonArray UTF8String] );
NSError * invalidPError;
NSData * ipiData = [NSJSONSerialization dataWithJSONObject:[response invalidProductIdentifiers] options:0 error:&invalidPError];
NSString * ipiString = [[NSString alloc] initWithData:ipiData encoding:NSUTF8StringEncoding];
FREDispatchStatusEventAsync(AirInAppCtx ,(uint8_t*) "PRODUCT_INFO_ERROR", (uint8_t*) [ipiString UTF8String]);

}
}
Expand Down Expand Up @@ -159,7 +162,12 @@ - (void) completeTransaction:(SKPaymentTransaction*)transaction
[data setValue:receiptString forKey:@"receipt"];
[data setValue:@"AppStore" forKey:@"receiptType"];

FREDispatchStatusEventAsync(AirInAppCtx, (uint8_t*)"PURCHASE_SUCCESSFUL", (uint8_t*)[[data JSONString] UTF8String]);
NSError * err;
NSData * transData = [NSJSONSerialization dataWithJSONObject:data options:0 error:&err];
NSString * transJsonString = [[NSString alloc] initWithData:transData encoding:NSUTF8StringEncoding];


FREDispatchStatusEventAsync(AirInAppCtx, (uint8_t*)"PURCHASE_SUCCESSFUL", (uint8_t*) [transJsonString UTF8String]);
}

// transaction failed, remove the transaction from the queue.
Expand All @@ -177,14 +185,20 @@ - (void) failedTransaction:(SKPaymentTransaction*)transaction
[data setValue:[[transaction error] localizedDescription] forKey:@"FailureDescription"];
[data setValue:[[transaction error] localizedRecoverySuggestion] forKey:@"RecoverySuggestion"];

NSString *error = transaction.error.code == SKErrorPaymentCancelled ? @"RESULT_USER_CANCELED" : [data JSONString];
NSString *error;
if(transaction.error.code == SKErrorPaymentCancelled) {
error = @"RESULT_USER_CANCELED";
} else {
NSError * err;
NSData * transData = [NSJSONSerialization dataWithJSONObject:data options:0 error:&err];
error = [[NSString alloc] initWithData:transData encoding:NSUTF8StringEncoding];
}

// conclude the transaction
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];

// dispatch event
FREDispatchStatusEventAsync(AirInAppCtx, (uint8_t*)"PURCHASE_ERROR", (uint8_t*) [error UTF8String]);

}

// transaction is being purchasing, logging the info.
Expand Down
251 changes: 0 additions & 251 deletions ios/JSONKit/JSONKit.h

This file was deleted.

Loading