capacitor-community / intercom

Enable Intercom for Capacitor apps
https://capacitorjs.com/docs
MIT License
60 stars 77 forks source link

Main Thread Checker: UI API called on a background thread when calling Intercom.registerUnidentifiedUser() #95

Open O-mkar opened 1 year ago

O-mkar commented 1 year ago

When calling Intercom.registerUnidentifiedUser() in the application, the Main Thread Checker reports a UI API call on a background thread with the following backtrace:

Main Thread Checker: UI API called on a background thread: -[UIApplication supportsMultipleScenes]
PID: 1506, TID: 73284, Thread name: (none), Queue name: bridge, QoS: 0
Backtrace:
4   Intercom                            0x00000001011eb894 IntercomSDK_PINRemoteImageManagerSubclassOverridesSelector + 814416
5   Intercom                            0x000000010116ad58 IntercomSDK_PINRemoteImageManagerSubclassOverridesSelector + 287252
6   Intercom                            0x000000010116a9b4 IntercomSDK_PINRemoteImageManagerSubclassOverridesSelector + 286320
7   Intercom                            0x0000000100f97960 Intercom + 31072
8   Intercom                            0x0000000100f96638 Intercom + 26168
9   Intercom                            0x0000000100f97c94 Intercom + 31892
10  CapacitorCommunityIntercom          0x00000001002e33f8 $s26CapacitorCommunityIntercom0C6PluginC24registerUnidentifiedUseryySo13CAPPluginCallCF + 64
11  CapacitorCommunityIntercom          0x00000001002e344c $s26CapacitorCommunityIntercom0C6PluginC24registerUnidentifiedUseryySo13CAPPluginCallCFTo + 52
12  Capacitor                           0x0000000100678000 $s9Capacitor0A6BridgeC12handleJSCall4callyAA0D0V_tFyycfU0_ + 856
13  Capacitor                           0x000000010066c4a8 $sIeg_IeyB_TR + 48
14  libdispatch.dylib                   0x0000000100568520 _dispatch_call_block_and_release + 32
15  libdispatch.dylib                   0x000000010056a038 _dispatch_client_callout + 20
16  libdispatch.dylib                   0x00000001005720b0 _dispatch_lane_serial_drain + 984
17  libdispatch.dylib                   0x0000000100572df4 _dispatch_lane_invoke + 412
18  libdispatch.dylib                   0x000000010057fc74 _dispatch_workloop_worker_thread + 736
19  libsystem_pthread.dylib             0x000000020216fddc _pthread_wqthread + 288
20  libsystem_pthread.dylib             0x000000020216fb7c start_wqthread + 8
2023-08-01 12:44:11.879635+0100 App[1506:73284] [reports] Main Thread Checker: UI API called on a background thread: -[UIApplication supportsMultipleScenes]
PID: 1506, TID: 73284, Thread name: (none), Queue name: bridge, QoS: 0
Backtrace:
4   Intercom                            0x00000001011eb894 IntercomSDK_PINRemoteImageManagerSubclassOverridesSelector + 814416
5   Intercom                            0x000000010116ad58 IntercomSDK_PINRemoteImageManagerSubclassOverridesSelector + 287252
6   Intercom                            0x000000010116a9b4 IntercomSDK_PINRemoteImageManagerSubclassOverridesSelector + 286320
7   Intercom                            0x0000000100f97960 Intercom + 31072
8   Intercom                            0x0000000100f96638 Intercom + 26168
9   Intercom                            0x0000000100f97c94 Intercom + 31892
10  CapacitorCommunityIntercom          0x00000001002e33f8 $s26CapacitorCommunityIntercom0C6PluginC24registerUnidentifiedUseryySo13CAPPluginCallCF + 64
11  CapacitorCommunityIntercom          0x00000001002e344c $s26CapacitorCommunityIntercom0C6PluginC24registerUnidentifiedUseryySo13CAPPluginCallCFTo + 52
12  Capacitor                           0x0000000100678000 $s9Capacitor0A6BridgeC12handleJSCall4callyAA0D0V_tFyycfU0_ + 856
13  Capacitor                           0x000000010066c4a8 $sIeg_IeyB_TR + 48
14  libdispatch.dylib                   0x0000000100568520 _dispatch_call_block_and_release + 32
15  libdispatch.dylib                   0x000000010056a038 _dispatch_client_callout + 20
16  libdispatch.dylib                   0x00000001005720b0 _dispatch_lane_serial_drain + 984
17  libdispatch.dylib                   0x0000000100572df4 _dispatch_lane_invoke + 412
18  libdispatch.dylib                   0x000000010057fc74 _dispatch_workloop_worker_thread + 736
19  libsystem_pthread.dylib             0x000000020216fddc _pthread_wqthread + 288
20  libsystem_pthread.dylib             0x000000020216fb7c start_wqthread + 8
2023-08-01 12:44:11.881516+0100 App[1506:72977] [Intercom] INFO - Registering an unidentified user.
This issue occurs when Intercom.registerUnidentifiedUser() is invoked. It seems to trigger UI API calls on a background thread, leading to the Main Thread Checker warnings.

Expected Behavior: The method Intercom.registerUnidentifiedUser() should not trigger UI API calls on background threads and should be executed on the main thread.

Steps to Reproduce:

Call Intercom.registerUnidentifiedUser() in the application.

Code:

  constructor(public platform: Platform) {
    Intercom.registerUnidentifiedUser();
}

Environment:

iOS version: iOS 16.4.1

ogaguinaga commented 1 year ago

I'm experiencing the same issue. Is this the reason why calling Intercom.registerUnidentifiedUser(); blocks the event loop? I have a button on my app with a click handler that looks like this:

const handleFeedback = async () => {
  isLoading.value = true;

  try {
    Intercom.registerUnidentifiedUser();
    Intercom.displayMessenger();
  } catch (error) {
    console.error("Error displaying Intercom messenger:", error);
  } finally {
    isLoading.value = false;
  }
};

on the button itself I display a loading state using the isLoading ref, however after clicking the button the whole app freezes and the loading state never shows. I'm guessing this is because the ref is set but Vue is not aware of it's change because Intercom.registerUnidentifiedUser(); is blocking the event loop. I also tried adding await nextTick(); after setting the loading state to true however that did not help either.

bastienlemaitre commented 1 year ago

Got same issue

KevinDelicity commented 1 year ago

Same issue for me...

dhconsults commented 3 months ago

ff