paypal / paypal-here-sdk-ios-distribution

Add credit card (tap, insert, swipe & key-in) capabilities to your iOS app
Other
81 stars 91 forks source link

PayPalRetailSDK initializeSDK exception #371

Closed asa47 closed 2 years ago

asa47 commented 2 years ago

Hello, we just updated the SDK from version 2.1.0320297000 to 2.3.0021182000. After calling [PayPalRetailSDK initializeSDK]; it throws the following exception:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]' *** First throw call stack: (0x1ad6ef114 0x1c0f8bcb4 0x1ad759398 0x1ad75702c 0x1ad5df490 0x1ad5da35c 0x101ef6a9c 0x104443db8 0x1044455fc 0x104453a6c 0x1ad66ec30 0x1ad6690e8 0x1ad668200 0x1c37e5598 0x1aff31bcc 0x1aff371a0 0x100f28434 0x1ad347588) libc++abi.dylib: terminating with uncaught exception of type NSException *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]' terminating with uncaught exception of type NSException

The SDK used to work fine with the previous version. Are we missing something? Is there any breaking change that we should be aware of?

Please let me know if you need additional informations.

EarthyOrange commented 2 years ago

Hello @asa47! Thank you for creating this bug report. Can you please also include further information along the following lines:

asa47 commented 2 years ago

Hello @EarthyOrange, please see the following and let me know if you need additional informations:

2021-08-13 13:14:32.239998+0100 POS[3584:148353] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: ' -[NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]' First throw call stack: (0x19d52125c 0x1b12b6480 0x19d58cab4 0x19d58a788 0x19d40fbac 0x19d40aaf8 0x103afec2c 0x10604bae8 0x10604d32c 0x10605b76c 0x19d4a0298 0x19d49a6f8 0x19d4997d0 0x1b3bdb570 0x19fdc62d0 0x19fdcb84c 0x102b1c034 0x19d178140) libc++abi: terminating with uncaught exception of type NSException Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]' terminating with uncaught exception of type NSException (lldb)



- Xcode and device version
Xcode: Version 12.5 (12E262)
MacBook Pro: MacBook Pro 15-inch 2017
Device: iOS 14.7.1 iPad (6th Generation)

- Does the sample app build and run in the same environment with the latest SDK?
Yes, it works on the sample app. It doesn't trigger the exception at `[PayPalRetailSDK initializeSDK];`

- Cocoapods version?
cocoapods-1.10.1
pod 1.10.1

- Were any changes made to the code/project to update to the latest SDK version other than pointing to a different pod version?
No, we only change the pod version from 2.1.0320297000 to 2.3.0021161010.
EarthyOrange commented 2 years ago

@asa47 Can you please add the code snippet, from your project, containing the [PayPalRetailSDK initializeSDK]; usage?

asa47 commented 2 years ago

@EarthyOrange This is what we do, and please let me know if you need additional informations:


- (void)initSDK:(CDVInvokedUrlCommand*)command
{
    [self.commandDelegate runInBackground:^{
          [PayPalRetailSDK initializeSDK]; // The app crash after triggering this method
    }];
}

- (void)performLogin:(CDVInvokedUrlCommand*)command 
{
     NSString* accessToken = [[command arguments] objectAtIndex:0];
     NSString* refreshUrl = [[command arguments] objectAtIndex:1];
     NSString* environment = [[command arguments] objectAtIndex:2];

     SdkCredential *sdkCreds = [[SdkCredential alloc] initWithAccessToken:accessToken refreshUrl:refreshUrl environment:environment];

     [PayPalRetailSDK initializeMerchantWithCredentials:sdkCreds completionHandler:^(PPRetailError *error, PPRetailMerchant* merchant) {
     // ..
     }];
}
shupaypal commented 2 years ago

@asa47 Thank you for sharing the code snippet. We will investigate the scenario for initializeSDK with runInBackground, but in the mean time, is it possible for you to try removing the initializeSDK code?

The initializeMerchantWithCredentials API takes care of initializing the SDK if it is not initialized already, so can you please check if just relying on performLogin alone helps in preventing the crash?

asa47 commented 2 years ago

@shupaypal Sorry for the late reply, we have looked into it and the crash is caused by wrapping the init call in the runInBackground method. We removed it from the code and now it is working fine.

I will close the issue and thanks again for the support!