带有Firebase的Google跟踪代码管理器导致iOS崩溃

时间:2020-04-29 20:17:03

标签: ios firebase google-tag-manager

我在我的应用程序中将Google跟踪代码管理器与Firebase一起使用。

这是我的代码,用于记录屏幕和事件:

import FirebaseAnalytics
import Foundation

public class AnalyticManager {
    public static func logScreen(_ name: String, className: String?) {
        Analytics.setScreenName(name, screenClass: className)
        Analytics.logEvent("open_screen", parameters: ["screenName": name])
    }
}

启动我的应用程序时,出现此崩溃:

2020-04-29 17:05:52.189148+0000 MyApp[15962:354528] -[__NSDictionaryM length]: unrecognized selector sent to instance 0x60000033a500
2020-04-29 17:05:52.191676+0000 MyApp[15962:354528] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM length]: unrecognized selector sent to instance 0x60000033a500'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000011719cf0e __exceptionPreprocess + 350
    1   libobjc.A.dylib                     0x00000001170089b2 objc_exception_throw + 48
    2   CoreFoundation                      0x00000001171bdc34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
    3   CoreFoundation                      0x00000001171a190c ___forwarding___ + 1436
    4   CoreFoundation                      0x00000001171a3bf8 _CF_forwarding_prep_0 + 120
    5   MyApp              0x000000010f9f597f -[GAIBatchingDispatcher queueDispatch:] + 385
    6   MyApp              0x000000010f9f57e4 -[GAIBatchingDispatcher queueModel:] + 125
    7   Foundation                          0x0000000114543f42 __NSThreadPerformPerform + 209
    8   CoreFoundation                      0x0000000117100eb1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    9   CoreFoundation                      0x0000000117100ddc __CFRunLoopDoSource0 + 76
    10  CoreFoundation                      0x00000001171005b4 __CFRunLoopDoSources0 + 180
    11  CoreFoundation                      0x00000001170fb1ae __CFRunLoopRun + 974
    12  CoreFoundation                      0x00000001170faac4 CFRunLoopRunSpecific + 404
    13  Foundation                          0x000000011452dd71 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 211
    14  Foundation                          0x000000011452df85 -[NSRunLoop(NSRunLoop) run] + 76
    15  MyApp              0x000000010f9e30b8 +[GAI threadMain:] + 62
    16  Foundation                          0x0000000114543aeb __NSThread__start__ + 1047
    17  libsystem_pthread.dylib             0x00007fff51b3b109 _pthread_start + 148
    18  libsystem_pthread.dylib             0x00007fff51b36b8b thread_start + 15
)
libc++abi.dylib: terminating with uncaught exception of type NSException

当我使用Google跟踪代码管理器6.0版时,该应用程序不会崩溃,但无法使用,原因是我需要Firebase的某些功能,这些功能要求最新版本的Firebase与Google跟踪代码管理器6.0不兼容

如何摆脱崩溃?谢谢你。

1 个答案:

答案 0 :(得分:0)

好吧,我找到了解决相同问题的解决方案,从事件名称中删除“ _”,所以我只替换了这一行:

Analytics.logEvent("open_screen", parameters: ["screenName": name])

具有:

Analytics.logEvent("openScreen", parameters: ["screenName": name])

成功了。