2015-04-20 67 views
0

使用iOS版本3.0.9(通常爲3.0.x)的Google Analytics庫,我們看到很多崩潰,如下所示。針對iOS的谷歌分析中的線程崩潰

他們似乎隨機發生。

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 

回答

1

事實證明,GAI庫不像它聲稱的那樣是線程安全的。我們通過序列化調用來解決Google Analytics(分析)崩潰問題。

 (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」以上),這迫使只有一個碼塊以一次執行代碼塊被執行。