Appboy / appboy-ios-sdk

Public repo for the Braze iOS SDK
https://www.braze.com
Other
164 stars 142 forks source link

[Bug]: Background Task will cause a risk of termination from [ABKService processRequest:] #352

Closed lucio1392 closed 1 year ago

lucio1392 commented 1 year ago

Platform

iOS

Platform Version

iOS 16.1.1

Braze SDK Version

4.5.2

Xcode Version

14.2

Integration Method

Cocoapods

Computer Processor

Apple (M1)

Repro Rate

100%

Steps To Reproduce

Example:

  1. Run the app with debugging.
  2. Put the app in the Background for more than 30 seconds.
  3. Wait for 30s or step 4
  4. Bring the app to The Foreground after 30s.
  5. Read the log from XCode console.

Expected Behavior

We should not get the warning log

[BackgroundTask] Background task still not ended after expiration handlers were called: <_UIBackgroundTaskInfo: 0x28030d540>: taskID = 19939, taskName = Called by Appboy_iOSSDK, from -[ABKService processRequest:], creationTime = 143988 (elapsed = 2). This app will likely be terminated by the system. Call UIApplication.endBackgroundTask(:) to avoid this.

Actual Incorrect Behavior

We got a log as below many times from XCode console.

[BackgroundTask] Background task still not ended after expiration handlers were called: <_UIBackgroundTaskInfo: 0x28030d540>: taskID = 19939, taskName = Called by Appboy_iOSSDK, from -[ABKService processRequest:], creationTime = 143988 (elapsed = 2). This app will likely be terminated by the system. Call UIApplication.endBackgroundTask(:) to avoid this.

Verbose Logs

[BackgroundTask] Background task still not ended after expiration handlers were called: <_UIBackgroundTaskInfo: 0x28030d7c0>: taskID = 19946, taskName = Called by Appboy_iOS_SDK, from -[ABKService processRequest:], creationTime = 143990 (elapsed = 0). This app will likely be terminated by the system. Call UIApplication.endBackgroundTask(_:) to avoid this.

Additional Information

Currently, my project uses Appboy version 4.3.4 but even after upgrading to the latest version, which is 4.5.2, this issue still happen.

lucio1392 commented 1 year ago

Hi @hokstuff , sorry for bothering you, but could you help to take a look ?

hokstuff commented 1 year ago

Hi @lucio1392,

Is this issue primarily around an issue in the logs, or are you experiencing any issues around the functionality when seeing the logs? I was able to find this thread with matching logs, but it doesn't have any resolution.

In our new Swift SDK, we have completely revamped our logic around background tasks, and this issue should be resolved when using it. Here is our migration guide to move from the Appboy SDK to the new SDK - let me know if you continue to have issues when using it. Thanks!

lucio1392 commented 1 year ago

Hi @hokstuff ,

I'm facing the issue that the app often gets terminated by iOS when the app is in the background. I did some investigations and saw the log that might cause the system to terminate the app, and it came from Appboy SDK. ( Please note that if you on debug mode, it will just show the log without terminating the app by the OS system )

If we do not correctly handle the background tasks, it will cause the system OS to terminate the app more often.

I will try your suggestion by moving to the new Appboy SDK and to see if it resolve the issue or not.

Thank you.

hokstuff commented 1 year ago

Just closing the loop here.

Here is the related public issue on the Braze Swift SDK. We have addressed the root cause in version 5.9.1 of the Swift SDK. For those who run into this issue as well, please migrate to that version or newer of the Swift SDK.

Thanks!