onnela-lab / beiwe-ios

Beiwe is a smartphone-based digital phenotyping research platform. This is the Beiwe iOS app code. The Beiwe2 app is also available on the Apple app store to use with open source builds of the Beiwe backend.
https://www.beiwe.org/
BSD 3-Clause "New" or "Revised" License
22 stars 14 forks source link

weird background error that Doesn't crash the app? #58

Open biblicabeebli opened 8 months ago

biblicabeebli commented 8 months ago

Getting these errors on at least my development build.... but not consistently. App doesn't crash. Am confused.

Main Thread Checker: UI API called on a background thread: -[UIApplication delegate]
PID: 34781, TID: 1988520, Thread name: (none), Queue name: com.apple.root.background-qos, QoS: 9
Backtrace:
4   GoogleUtilities                     0x0000000105c2468c __47+[GULAppDelegateSwizzler proxyOriginalDelegate]_block_invoke + 44
5   libdispatch.dylib                   0x000000010659ab34 _dispatch_client_callout + 20
6   libdispatch.dylib                   0x000000010659c690 _dispatch_once_callout + 140
7   GoogleUtilities                     0x0000000105c246ec +[GULAppDelegateSwizzler proxyOriginalDelegateIncludingAPNSMethods] + 44
8   Beiwe2                              0x00000001048d1950 -[FIRMessagingRemoteNotificationsProxy swizzleMethodsIfPossible] + 48
9   Beiwe2                              0x00000001048c18a4 -[FIRMessaging configureNotificationSwizzlingIfEnabled] + 128
10  Beiwe2                              0x00000001048c17cc __36+[FIRMessaging componentsToRegister]_block_invoke + 236
11  Beiwe2                              0x00000001048a2ae4 -[FIRComponentContainer instantiateInstanceForProtocol:withBlock:] + 68
12  Beiwe2                              0x00000001048a2c5c -[FIRComponentContainer instanceForProtocol:] + 184
13  Beiwe2                              0x00000001048c1350 +[FIRMessaging messaging] + 88
14  Beiwe2                              0x0000000104713d74 $s6Beiwe211AppDelegateC12firebaseLoopyyFyyYbcfU_ + 436
15  Beiwe2                              0x0000000104629b94 $sIegh_IeyBh_TR + 48
16  libdispatch.dylib                   0x0000000106598f50 _dispatch_call_block_and_release + 32
17  libdispatch.dylib                   0x000000010659ab34 _dispatch_client_callout + 20
18  libdispatch.dylib                   0x00000001065aef0c _dispatch_root_queue_drain + 968
19  libdispatch.dylib                   0x00000001065af6cc _dispatch_worker_thread2 + 188
20  libsystem_pthread.dylib             0x0000000219613928 _pthread_wqthread + 228
21  libsystem_pthread.dylib             0x0000000219613a04 start_wqthread + 8
Main Thread Checker: UI API called on a background thread: -[UIApplication delegate]
PID: 34781, TID: 1988520, Thread name: (none), Queue name: com.apple.root.background-qos, QoS: 9
Backtrace:
4   GoogleUtilities                     0x0000000105c2468c __47+[GULAppDelegateSwizzler proxyOriginalDelegate]_block_invoke + 44
5   libdispatch.dylib                   0x000000010659ab34 _dispatch_client_callout + 20
6   libdispatch.dylib                   0x000000010659c690 _dispatch_once_callout + 140
7   GoogleUtilities                     0x0000000105c246ec +[GULAppDelegateSwizzler proxyOriginalDelegateIncludingAPNSMethods] + 44
8   Beiwe2                              0x00000001048d1950 -[FIRMessagingRemoteNotificationsProxy swizzleMethodsIfPossible] + 48
9   Beiwe2                              0x00000001048c18a4 -[FIRMessaging configureNotificationSwizzlingIfEnabled] + 128
10  Beiwe2                              0x00000001048c17cc __36+[FIRMessaging componentsToRegister]_block_invoke + 236
11  Beiwe2                              0x00000001048a2ae4 -[FIRComponentContainer instantiateInstanceForProtocol:withBlock:] + 68
12  Beiwe2                              0x00000001048a2c5c -[FIRComponentContainer instanceForProtocol:] + 184
13  Beiwe2                              0x00000001048c1350 +[FIRMessaging messaging] + 88
14  Beiwe2                              0x0000000104713d74 $s6Beiwe211AppDelegateC12firebaseLoopyyFyyYbcfU_ + 436
15  Beiwe2                              0x0000000104629b94 $sIegh_IeyBh_TR + 48
16  libdispatch.dylib                   0x0000000106598f50 _dispatch_call_block_and_release + 32
17  libdispatch.dylib                   0x000000010659ab34 _dispatch_client_callout + 20
18  libdispatch.dylib                   0x00000001065aef0c _dispatch_root_queue_drain + 968
19  libdispatch.dylib                   0x00000001065af6cc _dispatch_worker_thread2 + 188
20  libsystem_pthread.dylib             0x0000000219613928 _pthread_wqthread + 228
21  libsystem_pthread.dylib             0x0000000219613a04 start_wqthread + 8
=================================================================
Main Thread Checker: UI API called on a background thread: -[UIApplication setDelegate:]
PID: 34781, TID: 1988520, Thread name: (none), Queue name: com.apple.root.background-qos, QoS: 9
Backtrace:
4   GoogleUtilities                     0x0000000105c24efc +[GULAppDelegateSwizzler reassignAppDelegate] + 88
5   GoogleUtilities                     0x0000000105c266fc +[GULAppDelegateSwizzler proxyAppDelegate:] + 132
6   GoogleUtilities                     0x0000000105c246ac __47+[GULAppDelegateSwizzler proxyOriginalDelegate]_block_invoke + 76
7   libdispatch.dylib                   0x000000010659ab34 _dispatch_client_callout + 20
8   libdispatch.dylib                   0x000000010659c690 _dispatch_once_callout + 140
9   GoogleUtilities                     0x0000000105c246ec +[GULAppDelegateSwizzler proxyOriginalDelegateIncludingAPNSMethods] + 44
10  Beiwe2                              0x00000001048d1950 -[FIRMessagingRemoteNotificationsProxy swizzleMethodsIfPossible] + 48
11  Beiwe2                              0x00000001048c18a4 -[FIRMessaging configureNotificationSwizzlingIfEnabled] + 128
12  Beiwe2                              0x00000001048c17cc __36+[FIRMessaging componentsToRegister]_block_invoke + 236
13  Beiwe2                              0x00000001048a2ae4 -[FIRComponentContainer instantiateInstanceForProtocol:withBlock:] + 68
14  Beiwe2                              0x00000001048a2c5c -[FIRComponentContainer instanceForProtocol:] + 184
15  Beiwe2                              0x00000001048c1350 +[FIRMessaging messaging] + 88
16  Beiwe2                              0x0000000104713d74 $s6Beiwe211AppDelegateC12firebaseLoopyyFyyYbcfU_ + 436
17  Beiwe2                              0x0000000104629b94 $sIegh_IeyBh_TR + 48
18  libdispatch.dylib                   0x0000000106598f50 _dispatch_call_block_and_release + 32
19  libdispatch.dylib                   0x000000010659ab34 _dispatch_client_callout + 20
20  libdispatch.dylib                   0x00000001065aef0c _dispatch_root_queue_drain + 968
21  libdispatch.dylib                   0x00000001065af6cc _dispatch_worker_thread2 + 188
22  libsystem_pthread.dylib             0x0000000219613928 _pthread_wqthread + 228
23  libsystem_pthread.dylib             0x0000000219613a04 start_wqthread + 8
Main Thread Checker: UI API called on a background thread: -[UIApplication setDelegate:]
PID: 34781, TID: 1988520, Thread name: (none), Queue name: com.apple.root.background-qos, QoS: 9
Backtrace:
4   GoogleUtilities                     0x0000000105c24efc +[GULAppDelegateSwizzler reassignAppDelegate] + 88
5   GoogleUtilities                     0x0000000105c266fc +[GULAppDelegateSwizzler proxyAppDelegate:] + 132
6   GoogleUtilities                     0x0000000105c246ac __47+[GULAppDelegateSwizzler proxyOriginalDelegate]_block_invoke + 76
7   libdispatch.dylib                   0x000000010659ab34 _dispatch_client_callout + 20
8   libdispatch.dylib                   0x000000010659c690 _dispatch_once_callout + 140
9   GoogleUtilities                     0x0000000105c246ec +[GULAppDelegateSwizzler proxyOriginalDelegateIncludingAPNSMethods] + 44
10  Beiwe2                              0x00000001048d1950 -[FIRMessagingRemoteNotificationsProxy swizzleMethodsIfPossible] + 48
11  Beiwe2                              0x00000001048c18a4 -[FIRMessaging configureNotificationSwizzlingIfEnabled] + 128
12  Beiwe2                              0x00000001048c17cc __36+[FIRMessaging componentsToRegister]_block_invoke + 236
13  Beiwe2                              0x00000001048a2ae4 -[FIRComponentContainer instantiateInstanceForProtocol:withBlock:] + 68
14  Beiwe2                              0x00000001048a2c5c -[FIRComponentContainer instanceForProtocol:] + 184
15  Beiwe2                              0x00000001048c1350 +[FIRMessaging messaging] + 88
16  Beiwe2                              0x0000000104713d74 $s6Beiwe211AppDelegateC12firebaseLoopyyFyyYbcfU_ + 436
17  Beiwe2                              0x0000000104629b94 $sIegh_IeyBh_TR + 48
18  libdispatch.dylib                   0x0000000106598f50 _dispatch_call_block_and_release + 32
19  libdispatch.dylib                   0x000000010659ab34 _dispatch_client_callout + 20
20  libdispatch.dylib                   0x00000001065aef0c _dispatch_root_queue_drain + 968
21  libdispatch.dylib                   0x00000001065af6cc _dispatch_worker_thread2 + 188
22  libsystem_pthread.dylib             0x0000000219613928 _pthread_wqthread + 228
23  libsystem_pthread.dylib             0x0000000219613a04 start_wqthread + 8
biblicabeebli commented 8 months ago

This is the content of the function, we are trying to call that inside main.async. is that wrong?

    func firebaseLoop() {
        // The app cannot register with firebase until it gets a token, which only occurs at registration time, and it needs access to the appDelegate.
        // This must be called after FirebaseApp.configure(), so we dispatch it and wait until the app is initialized from RegistrationViewController...
        GLOBAL_BACKGROUND_QUEUE.async {
            while !StudyManager.real_study_loaded {
                sleep(1) // print("waiting for study to load")
            }
            while FirebaseApp.app() == nil { // FirebaseApp.app() emits the firebase spam log
                sleep(1) // print("waiting firbase app to be ready")
            }
            Messaging.messaging().delegate = self
            UNUserNotificationCenter.current().delegate = self
            // App crashes if this isn't called on main thread
            DispatchQueue.main.async {
                UIApplication.shared.registerForRemoteNotifications()
                if let token = Messaging.messaging().fcmToken {
                    self.sendFCMToken(fcmToken: token)
                }
            }
        }
    }