teads / TeadsSDK-iOS

Teads SDK for iOS - Premium branded "outstream" ads
https://support.teads.tv/support/solutions/articles/36000314785-ios-sdk-developer-guide
MIT License
27 stars 11 forks source link

Main thread checker issue on ad click #245

Open v-andreipetrea opened 1 month ago

v-andreipetrea commented 1 month ago

Hi @github-lucas-bon,

Is it expected to call "willPresentModalView" on a background thread? Normally, at this point, the application or the SDK tries to determine which is the current top most UIViewController. In the example below I will return nil on the "willPresentModalView" callback and the Main Thread Checker is triggered. It's reproducible on the latest Teads SDK v5.1.3 after tapping on a video ad.

Could you please look into this and try to resolve the main thread warning?

    public func willPresentModalView(ad: TeadsAd) -> UIViewController? {
        return nil
    }
=================================================================
Main Thread Checker: UI API called on a background thread: -[UIView nextResponder]
PID: 38013, TID: 1546556, Thread name: (none), Queue name: com.teads.adcore.jsengine, QoS: 0
Backtrace:
4   TeadsSDK                            0x0000000107614c78 block_destroy_helper.21 + 3488
5   TeadsSDK                            0x00000001076013d0 block_destroy_helper.21 + 760
6   TeadsSDK                            0x00000001076016f4 block_destroy_helper.21 + 1564
7   TeadsSDK                            0x000000010764703c block_destroy_helper + 9436
8   TeadsSDK                            0x0000000107644f14 block_destroy_helper + 948
9   CoreFoundation                      0x00000001a2c59b24 6B22DD81-3585-3BE6-BC77-BA19810EC0F2 + 138020
10  CoreFoundation                      0x00000001a2c77610 6B22DD81-3585-3BE6-BC77-BA19810EC0F2 + 259600
11  JavaScriptCore                      0x00000001ae30ee34 E76B377F-C862-395A-9439-D12B09A59E07 + 4668980
12  JavaScriptCore                      0x00000001ae30e830 E76B377F-C862-395A-9439-D12B09A59E07 + 4667440
13  JavaScriptCore                      0x00000001ae30c9b8 E76B377F-C862-395A-9439-D12B09A59E07 + 4659640
14  JavaScriptCore                      0x00000001ae2a2fa8 E76B377F-C862-395A-9439-D12B09A59E07 + 415226984
15  JavaScriptCore                      0x00000001ae29f848 E76B377F-C862-395A-9439-D12B09A59E07 + 4212808
16  JavaScriptCore                      0x00000001ae29f848 E76B377F-C862-395A-9439-D12B09A59E07 + 4212808
17  JavaScriptCore                      0x00000001ae29f790 E76B377F-C862-395A-9439-D12B09A59E07 + 4212624
18  JavaScriptCore                      0x00000001ae29f848 E76B377F-C862-395A-9439-D12B09A59E07 + 4212808
19  JavaScriptCore                      0x00000001ae29f848 E76B377F-C862-395A-9439-D12B09A59E07 + 4212808
20  JavaScriptCore                      0x00000001ae275780 E76B377F-C862-395A-9439-D12B09A59E07 + 4040576
21  JavaScriptCore                      0x00000001aea6dda4 E76B377F-C862-395A-9439-D12B09A59E07 + 12397988
22  JavaScriptCore                      0x00000001aed35538 _ZN3JSC8evaluateEPNS_14JSGlobalObjectERKNS_10SourceCodeENS_7JSValueERN3WTF8NakedPtrINS_9ExceptionEEE + 236
23  JavaScriptCore                      0x00000001ae316700 JSEvaluateScript + 584
24  JavaScriptCore                      0x00000001ade9d158 E76B377F-C862-395A-9439-D12B09A59E07 + 8536
25  TeadsSDK                            0x000000010760aff8 block_destroy_helper + 6932
26  TeadsSDK                            0x00000001075d8b5c block_destroy_helper + 6184
27  libdispatch.dylib                   0x0000000107240c70 _dispatch_call_block_and_release + 32
28  libdispatch.dylib                   0x00000001072427c0 _dispatch_client_callout + 20
29  libdispatch.dylib                   0x000000010724a8a4 _dispatch_lane_serial_drain + 984
30  libdispatch.dylib                   0x000000010724b5e0 _dispatch_lane_invoke + 428
31  libdispatch.dylib                   0x0000000107258168 _dispatch_workloop_worker_thread + 908
32  libsystem_pthread.dylib             0x0000000213e690bc _pthread_wqthread + 288
33  libsystem_pthread.dylib             0x0000000213e68e5c start_wqthread + 8
github-lucas-bon commented 1 month ago

Hello thanks for reporting it. You are going to take a look, we keep you posted cc @github-richard-depierre

github-richard-depierre commented 1 month ago

Hi @v-andreipetrea,

According to the documentation, the “willPresentModalView” event is not called in the main thread. It’s expected behavior as stated in the Teads SDK documentation. However, triggering the Main Thread Checker warning can indeed indicate an issue that needs addressing.

We can’t seem to be able to reproduce this error in the sample app. If possible, could you provide a fork of the sample app with the issue? This would help us investigate and provide more targeted assistance.

If you need further assistance or clarification on how to handle this, feel free to ask!

v-andreipetrea commented 1 month ago

Hi @github-richard-depierre,

Sure, I just created a fork, here's the branch I pushed: https://github.com/v-andreipetrea/TeadsSDK-iOS/tree/main-thread-issue-on-ad-click-inread-direct-tableview

I just modified the willPresentModalView return value to be nil for InReadDirect scrollView and tableView implementation to show the main thread issue appeared on ad click/tap.

Please let me know your thoughts on this and if you manage to reproduce the issue.

Thanks!

Screenshot 2024-05-16 at 15 42 13

v-andreipetrea commented 1 month ago

Hi @github-richard-depierre, did you get the chance to look into this?