Getting EXC_BAD_ACCESS in xcode 8+ when trying to use any purchase plugin


#1

Not really sure what is causing this problem, but when I’m trying to use any purchase plugin ( cordova-plugin-inapppurchase or cordova-plugin-purchase) I get this error in xcode

EXC_BAD_ACCESS (code=1, address=0x....)

and the app crashes… the interesting thing is, it’s not happening always, but most of the time. the code crashes in cordova-plugin-purchase ( i put * before the line )

- (void) purchase: (CDVInvokedUrlCommand*)command
{
    DLog(@"About to do IAP");
    id identifier = [command.arguments objectAtIndex:0];
    id quantity =   [command.arguments objectAtIndex:1];

    SKMutablePayment *payment = [SKMutablePayment paymentWithProduct:[self.list objectForKey:identifier]];
    if ([quantity respondsToSelector:@selector(integerValue)]) {
        payment.quantity = [quantity integerValue];
    }

    *********** [[SKPaymentQueue defaultQueue] addPayment:payment];

}

and it crashes here in cordova-plugin-inapppurchase:

- (void)addPayment:(NSString*)productIdentifier
              user:(NSString*)userIdentifier
           success:(void (^)(SKPaymentTransaction *transaction))successBlock
           failure:(void (^)(SKPaymentTransaction *transaction, NSError *error))failureBlock
{
    SKProduct *product = [self productForIdentifier:productIdentifier];
    if (product == nil)
    {
        RMStoreLog(@"unknown product id %@", productIdentifier)
        if (failureBlock != nil)
        {
            NSError *error = [NSError errorWithDomain:RMStoreErrorDomain code:RMStoreErrorCodeUnknownProductIdentifier userInfo:@{NSLocalizedDescriptionKey: NSLocalizedStringFromTable(@"Unknown product identifier", @"RMStore", @"Error description")}];
            failureBlock(nil, error);
        }
        return;
    }
    SKMutablePayment *payment = [SKMutablePayment paymentWithProduct:product];
    if ([payment respondsToSelector:@selector(setApplicationUsername:)])
    {
        payment.applicationUsername = userIdentifier;
    }
    
    RMAddPaymentParameters *parameters = [[RMAddPaymentParameters alloc] init];
    parameters.successBlock = successBlock;
    parameters.failureBlock = failureBlock;
    _addPaymentParameters[productIdentifier] = parameters;
    
    ********** [[SKPaymentQueue defaultQueue] addPayment:payment];
}

not really sure where to look, when I compile the app in xcode 7.3 this problem is not present (i have others unfortunately, so i have to use xcode 8)

if anyone has any similar issues, and found a solution, please let me know …

thanks!


#2

I have been trying to solve this with no success so far. I tried to use different cordova versions, different cordova-ios versions and different versions of the plugin, the result is the same - the app crashes. The most frustrating thing is, sometimes it works, sometimes (most of the times) it does not … and there’s a pattern (sort of) when I run the app in XCode it usually works the first time, then if i kill the app, and start it from the phone it dies, then if I go to multitasking and click on the app again then it works … the app dies right before (or maybe during) the purchase dialog appears. I have tried to create a totally new application, and reproduce the problem, could not do it - it showed the purchase dialog every time. Here is the plugin list,

cc.fovea.cordova.purchase 6.0.0 "Purchase"
com.verso.cordova.clipboard 0.1.0 "Clipboard"
cordova-custom-config 3.1.2 "cordova-custom-config"
cordova-plugin-camera 2.3.1 "Camera"
cordova-plugin-compat 1.1.0 "Compat"
cordova-plugin-device 1.1.4 "Device"
cordova-plugin-email 1.2.2 "EmailComposer"
cordova-plugin-facebook4 1.7.4 "Facebook Connect"
cordova-plugin-file 4.3.1 "File"
cordova-plugin-file-transfer 1.6.1 "File Transfer"
cordova-plugin-geolocation 2.4.1 "Geolocation"
cordova-plugin-inappbrowser 1.5.0 "InAppBrowser"
cordova-plugin-nativeaudio 3.0.7 "Cordova Native Audio"
cordova-plugin-splashscreen 4.0.1 "Splashscreen"
cordova-plugin-sqlite-2 1.0.4 "SQLitePlugin"
cordova-plugin-whitelist 1.3.1 "Whitelist"
cordova.plugins.diagnostic 3.3.2 "Diagnostic"
cordova_app_version_plugin 0.2.6 "getAppVersion"
ionic-plugin-deploy 0.6.5 "IonicDeploy"
ionic-plugin-keyboard 2.2.1 "Keyboard"
onesignal-cordova-plugin 2.0.10 "OneSignal Push Notifications"

maybe it has something to do with that … the more I’m trying to debug this, the more question I have. Any tip, idea help with this issue would be much appreciated.


#3

Looks like that the problem is caused by OneSignal plugin higher than 2.0.4 , when it’s downgraded to 2.0.4 it stops crashing. related issue: https://github.com/j3k0/cordova-plugin-purchase/issues/537