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

Drop-In UI crashes on iOS 9.x #219

Closed
fraggjkee opened this issue Feb 10, 2016 · 11 comments
Closed

Drop-In UI crashes on iOS 9.x #219

fraggjkee opened this issue Feb 10, 2016 · 11 comments

Comments

@fraggjkee
Copy link

Hello everyone,

I've successfully integrated Braintree SDK in our Android project but currently struggling with Braintree SDK v4.2.1 for iOS. I'm using the Drop-In UI, here's my code (copy-pasted from the official documentation):

Controller:

#import "BraintreeCore.h"
#import "BraintreeUI.h"

@interface ECCheckoutViewController () <BTDropInViewControllerDelegate>

@property (nonatomic, strong) ClientToken *clientToken;
@property (nonatomic, strong) BTAPIClient *braintreeClient;

@end

@implementation ECCheckoutViewController

- (void)showDropInUI {
    // Init BraintreeClient with a client token
    NSString *clientTokenValue = [_clientToken clientToken];
    _braintreeClient = [[BTAPIClient alloc] initWithAuthorization:clientTokenValue];

    BTDropInViewController *dropInViewController = [[BTDropInViewController alloc]
                                                    initWithAPIClient:self.braintreeClient];
    dropInViewController.delegate = self;

    UIBarButtonItem *item = [[UIBarButtonItem alloc]
                             initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
                             target:self
                             action:@selector(userDidCancelPayment)];
    dropInViewController.navigationItem.leftBarButtonItem = item;
    UINavigationController *navigationController = [[UINavigationController alloc]
                                                    initWithRootViewController:dropInViewController];
    [self presentViewController:navigationController animated:YES completion:nil];
}

#pragma mark - Braintree

- (void)dropInViewController:(BTDropInViewController*)viewController
  didSucceedWithTokenization:(BTPaymentMethodNonce*)paymentMethodNonce {

    // Send payment method nonce to your server for processing
    [self postOrderWithNonce:paymentMethodNonce.nonce];
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)dropInViewControllerDidCancel:(__unused BTDropInViewController *)viewController {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)userDidCancelPayment {
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end

AppDelegate:

#import "BraintreeCore.h"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Braintree
    [BTAppSwitch setReturnURLScheme:@"<bundle_id>.payments"];
}

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
            options:(NSDictionary *)options {

    if ([url.scheme localizedCaseInsensitiveCompare:@"<bundle_id>.payments"] == NSOrderedSame) {
        NSString *sourceApplication = [options objectForKey:UIApplicationOpenURLOptionsSourceApplicationKey];
        return [BTAppSwitch handleOpenURL:url sourceApplication:sourceApplication];
    }

    return YES;
}

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {

    NSDictionary *options = @{UIApplicationOpenURLOptionsSourceApplicationKey: sourceApplication,
                              UIApplicationOpenURLOptionsAnnotationKey: annotation};

    return [self application:application openURL:url options:options];
}

LSApplicationQueriesSchemes:
2016-02-10 22 32 36

URL types:
2016-02-10 22 34 09

The Drop-In controller appears on the screen correctly, then I press the PayPal button and the app crashes almost immediately with the following error:

2016-02-10 22:15:01.663 Some Project[9573:4321387] *** Assertion failure in +[PPOTSimpleKeychain setData:forKey:], /Users/fraggjkee/Dropbox/Work/_iOS/SomeProject-ios/Pods/Braintree/BraintreePayPal/PayPalUtils/PPOTSimpleKeychain.m:81
2016-02-10 22:15:01.668 Some Project[9573:4321387] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Received -34018 from SecItemCopyMatching!'

2016-02-10 22 21 38

ApplicationDelegate's methods aren't get called, the Drop-UI stays on the screen in a moment of crash. Any ideas what I am doing wrong guys? PayPall works quite well on iOS 8.4, by the way. Thanks in advance.

@skunkworks
Copy link
Contributor

Hi @fraggjkee, I'll take a look right now.

@skunkworks
Copy link
Contributor

Your implementation looks good.

The crash is caused by PayPal One Touch interacting with the iOS Keychain and getting back an error. I'm a bit concerned that you may be running into a bug with iOS itself:

SecItemAdd and SecItemCopyMatching returns error code -34018

It might be worthwhile to try out a few of the solutions posted there.

Are there certain scenarios where this crash occurs, or does it occur 100% of the time? Simulator or device?

@fraggjkee
Copy link
Author

@skunkworks thank you for the quick response. I've enabled "KeyChain Sharing" as some people suggest at SO but unfortunately it didn't help. Will try other solutions tomorrow.

The crash always occurs on my physical device (iPhone 6 with the latest iOS version) but simulators work stable so far (both 8.x and 9.x).

@ryanphillipthomas
Copy link

Hi @skunkworks wanted to chime in and report I'm hitting the same issue here. Instead it's occurring in the app delegate and occurs during app startup. It's not 100% of the time and occurs on a physical device. I'm looking into the solutions you posted above.

@ryanphillipthomas
Copy link

@skunkworks Can you confirm that removing the paypal payment integration, but still having the drop in ui function with the normal payment options would avoid the crash all together?

@skunkworks
Copy link
Contributor

@ryanphillipthomas You are correct that removing the PayPal subspec will work around this crash. We are actively investigating this issue and will report back with findings.

@skunkworks
Copy link
Contributor

@ryanphillipthomas Are you able to duplicate this crash when the device is not connected to the Xcode debugger?

@ryanphillipthomas
Copy link

Hey @skunkworks thanks for getting back to me. I haven't hit it yet without being attached to debugger, in all of my runs I do recall being attached. That said the crash is so random.. I haven't been able to identify steps to repro. It's hard to tell if the issue would present itself when its not connected. Some research into soffes/SAMKeychain#52 shows most people are hitting it when debugging, but some are also reporting it on production as well.

@skunkworks
Copy link
Contributor

Thanks for the quick response. Our tentative plan is to remove the assertion and find a way to recover gracefully if the keychain error occurs.

@skunkworks
Copy link
Contributor

Hi, version 4.2.3 should prevent Keychain errors from asserting and crashing. Thanks for your guys' help!

@ryanphillipthomas
Copy link

Thanks @skunkworks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants