[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
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.
tipsi-stripe version: 7.5.0Xcode run log: https://gist.github.com/minextu/d5bcd9d30b445a21c37394cc9a5819bc
Minimal example (react-native init + cocoapods + tipsi-stripe):
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!
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.mfixed 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.