适用于iOS的Google Analytics(分析)中的线程崩溃 [英] Threading crash in Google Analytics for iOS

查看:140
本文介绍了适用于iOS的Google Analytics(分析)中的线程崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用适用于iOS 3.0.9(通常为3.0.x)的Google Analytics(分析)库,我们会看到很多崩溃,如下面的崩溃.

Using the Google Analytics library for iOS version 3.0.9, (and 3.0.x in general), we see a lot of crashes like the one below.

它们似乎是随机发生的.

They appeared to occur randomly.

Exception Type:  SIGBUS
Exception Codes: BUS_ADRALN at 0xe756c0
Crashed Thread:  19

Thread 19 Crashed:
0   libsystem_platform.dylib            0x39e02e18 0x39e01000 + 7704
1   CoreFoundation                      0x2bfd0d6f 0x2bf92000 + 257391
2   CoreFoundation                      0x2c0716a3 0x2bf92000 + 915107
3   CoreFoundation                      0x2c070417 0x2bf92000 + 910359
4   CoreFoundation                      0x2bfd4a0b 0x2bf92000 + 272907
5   Communicator                        0x00714541 +[GAIUsageTracker trackTarget:action:] + 193
6   Communicator                        0x007049b3 -[GAITrackerImpl send:] + 47
7   Communicator                        0x00157b8d __66+[xxx]_block_invoke (xxx.m:305)
8   libdispatch.dylib                   0x39ca58cb 0x39ca4000 + 6347
9   libdispatch.dylib                   0x39caeda3 0x39ca4000 + 44451
10  libdispatch.dylib                   0x39cafcd7 0x39ca4000 + 48343
11  libsystem_pthread.dylib             0x39e06e31 0x39e06000 + 3633

推荐答案

事实证明,GAI库并不像它声称的那样具有线程安全性.我们可以通过序列化呼叫来解决Google Analytics(分析)崩溃的问题.

It turns out that the GAI library is not as thread-safe as it claims. We were able to fix our Google Analytics crashes by serializing the calls.

      (void (^)(void))block = {
       // your analytics call, eg
       [[[GAI sharedInstance] defaultTracker] send:....];
      };
      static dispatch_queue_t theQueue;
      static dispatch_once_t onceToken;
      dispatch_once(&onceToken, ^{
        theQueue = dispatch_queue_create("Analytics Queue", DISPATCH_QUEUE_SERIAL);
      });

      dispatch_async(theQueue, block);

因此,对跟踪器的所有调用都在序列化到同一队列(上面的"theQueue")的代码块中执行,这强制一次仅执行一个代码块.

So all calls to the tracker are executed in code blocks serialized on the same queue ("theQueue" above), which forces only one code block to execute at a time.

这篇关于适用于iOS的Google Analytics(分析)中的线程崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆