Tipsi-stripe: iOS: createSourceWithParams redirect fails with "Software caused connection abort"

Created on 21 Jun 2019  路  2Comments  路  Source: tipsi/tipsi-stripe

Before I have submitted the issue

[x] I have read an installation guide
[x] I know that for an iOS I need to install pods because I've read the installation guide
[x] I have read a linking guide and checked that everything is OK like in manual linking guide
[x] I know that before using tipsi-stripe I need to set options for my app as described in usage guide

The problem

When running createSourceWithParams() and specifying alipay as type, I get a promise rejection most of the time.
The error message says The operation couldn't be completed. Software caused connection abort.
This happens after the redirect back to my app.
It only happens on iOS and only on real hardware. I couldn't reproduce it on a simulator.

I haven't really looked into tipsi-stripe's source code yet, but this should only happen if a http request runs while the app goes into the background. In that case there should be a background task (https://forums.developer.apple.com/thread/85066). But from what I understand, the request is made before the redirect occurs, so there shouldn't be a problem.

Environment

  • tipsi-stripe version: 7.5.0
  • iOS or Android: iOS
  • OS version: 12.3.0
  • React-Native version: 0.59.9

Links to logs and sources

Xcode run log: https://gist.github.com/minextu/d5bcd9d30b445a21c37394cc9a5819bc

Code To Reproduce Issue (Good To Have)

Minimal example (react-native init + cocoapods + tipsi-stripe):

https://github.com/minextu/tipsi-stripe-alipay-test

wont-fix

Most helpful comment

This seems to be caused by a bug on iOS. When making a request directly after returning to the app, iOS seems to treat those requests as background requests and sometimes cancels them. A better explanation can be found here: https://github.com/AFNetworking/AFNetworking/issues/4279#issuecomment-447108981

For me adding this code to my AppDelegate.m fixed the issue. It will keep the app running in the background for a few minutes so that any requests made after returning won't fail.

 UIBackgroundTaskIdentifier backgroundTask;

- (void)applicationWillResignActive:(UIApplication *)application {
  backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
    [self endBackgroundTask];
  }];
}

- (void)endBackgroundTask {
  [[UIApplication sharedApplication] endBackgroundTask:(backgroundTask)];
  backgroundTask = UIBackgroundTaskInvalid;
}

All 2 comments

This seems to be caused by a bug on iOS. When making a request directly after returning to the app, iOS seems to treat those requests as background requests and sometimes cancels them. A better explanation can be found here: https://github.com/AFNetworking/AFNetworking/issues/4279#issuecomment-447108981

For me adding this code to my AppDelegate.m fixed the issue. It will keep the app running in the background for a few minutes so that any requests made after returning won't fail.

 UIBackgroundTaskIdentifier backgroundTask;

- (void)applicationWillResignActive:(UIApplication *)application {
  backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
    [self endBackgroundTask];
  }];
}

- (void)endBackgroundTask {
  [[UIApplication sharedApplication] endBackgroundTask:(backgroundTask)];
  backgroundTask = UIBackgroundTaskInvalid;
}

@minextu

Your solution worked like a charm, Thanks a lot!

Was this page helpful?
0 / 5 - 0 ratings