在用Objective-C编写的一个SDK库中,我们面临着iOS崩溃的问题。该Objective-C库正在从我们的客户开发的swift应用程序中调用。
以下是我们的sdk中创建多个线程的代码段:-
//Create a queue to collect attributes in parallel
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
//Create group to wait on the task scheduled in global queue
dispatch_group_t group = dispatch_group_create();
// Collect all information1
dispatch_group_async(group, queue, ^{
info1 = [self getInformation1];
});
// Collect all information2
dispatch_group_async(group, queue, ^{
info2 = [self getInformation2];
});
// Collect all information3
dispatch_group_async(group, queue, ^{
info3 = [self getInformation3];
});
// Collect all information4
dispatch_group_async(group, queue, ^{
info4 = [self getInformation4];
});
// Collect all information5
dispatch_group_async(group, queue, ^{
info5 = [self getInformation5];
});
// wait on the group to block the current thread.
int64_t time_delay = 3.0;
dispatch_time_t timeout = dispatch_time(DISPATCH_TIME_NOW, time_delay * NSEC_PER_SEC);
long success = dispatch_group_wait(group,timeout);
if(success != 0) {
//Log data to check which bucket is not complete
[Logger writeLogWithSeverity:kLogERROR message:info1];
[Logger writeLogWithSeverity:kLogERROR message:info2];
[Logger writeLogWithSeverity:kLogERROR message:info3];
[Logger writeLogWithSeverity:kLogERROR message:info4];
[Logger writeLogWithSeverity:kLogERROR message:info5];
}
这是理想的方法还是有更好的方法来创建并发线程?
1)
异常类型:EXC_BAD_ACCESS(SIGBUS) 异常代码:0x00000000 at 0x0000000323f7bec8 损坏的线程:0
线程0崩溃: 0 libobjc.A.dylib 0x000000018193c1a0 0x181918000 + 147872(objc_retain + 16) 1 abcMobile 0x0000000104365cbc 0x1041c8000 + 1694908-[DeviceInventory notifyCollectingdeviceInfo:](DeviceInventory.m:215 + 28) 2 abcMobile 0x0000000104365b78 0x1041c8000 + 1694584-[DeviceInventory startCollectingdeviceInfo](DeviceInventory.m:206 + 0) 3 libdispatch.dylib 0x0000000182058b24 0x182057000 + 6948(+ 24) 4 libdispatch.dylib 0x0000000182058ae4 0x182057000 + 6884(+ 16) 5 libdispatch.dylib 0x00000001820656e0 0x182057000 + 59104(+ 1012) 6 CoreFoundation 0x000000018270f070 0x182621000 + 974960(+ 12) 7 CoreFoundation 0x000000018270cbc8 0x182621000 + 965576(+ 2272) 8 CoreFoundation 0x000000018262cda8 0x182621000 + 48552(CFRunLoopRunSpecific + 552) 9 GraphicsServices 0x000000018460f020 0x184604000 + 45088(GSEventRunModal + 100) 10 UIKit 0x000000018c60d78c 0x18c2f0000 + 3266444(UIApplicationMain + 236) 11 abcMobile 0x00000001041ccc40 0x1041c8000 + 19520 main(main.swift:14 + 20) 12 libdyld.dylib 0x00000001820bdfc0 0x1820bd000 + 4032(+ 4)
崩溃代码:-[self.delegate didCompletedCollectingInformation:deviceInfo];
didCompletedCollectingInformation是回调函数
2)
异常类型:EXC_BAD_ACCESS(SIGBUS) 异常代码:0x00000000 at 0x00000007943dbec8 损坏的线程:18
线程18崩溃: 0 libobjc.A.dylib 0x0000000182f3c1a0 0x182f18000 + 147872(objc_retain + 16) 1 abcMobile 0x0000000100c0150c 0x100a64000 + 1692940-[DeviceInventory didFailWithError:](DeviceInventory.m:144 + 28) 2 CoreFoundation 0x0000000183cf8c3c 0x183c21000 + 883772(+ 20) 3 CoreFoundation 0x0000000183cf81b8 0x183c21000 + 881080(+ 428) 4 CoreFoundation 0x0000000183cf7f14 0x183c21000 + 880404(+ 216) 5 CoreFoundation 0x0000000183d7584c 0x183c21000 + 1394764(+ 1408) 6 CoreFoundation 0x0000000183c2ef38 0x183c21000 + 57144(_CFXNotificationPost + 384) 7基金会0x000000018469fbbc 0x184699000 + 27580(+ 68) 8 abcMobile 0x0000000100bf7f80 0x100a64000 + 1654656 + [错误sendErrorNotifactionForErrorCode:](Errors.m:405 + 64) 9 abcMobile 0x0000000100bf101c 0x100a64000 + 1626140 + [NetworkInfo information1](NetworkInfo.m:711 + 0) 10 abcMobile 0x0000000100bfb9fc 0x100a64000 + 1669628-[服务信息1](Services.m:391 + 20) 11 abcMobile 0x0000000100c058b4 0x100a64000 + 1710260-[DeviceInventory getInformation1](DeviceInventory.m:635 + 56) 12 abcMobile 0x0000000100c0268c 0x100a64000 + 1697420 __39- [DeviceInventory getdeviceInfo] _block_invoke.163(DeviceInventory.m:256 + 16) 13 libdispatch.dylib 0x0000000183658aa0 0x183657000 + 6816(+ 24) 14 libdispatch.dylib 0x0000000183658a60 0x183657000 + 6752(+ 16) 15 libdispatch.dylib 0x000000018369a5f0 0x183657000 + 275952(+ 1148) 16 libdispatch.dylib 0x000000018369a110 0x183657000 + 274704(+ 112) 17 libsystem_pthread.dylib 0x000000018398bfac 0x18398b000 + 4012(_pthread_wqthread + 1176)
崩溃代码:-if([self.delegate responsesToSelector:@selector(didFailWithError:)])
在这里,didFailWithError是一个回调函数
我们无法找到此崩溃的根本原因,因为这是非常随机的问题。有谁知道如何解决此崩溃问题? 当我们对这个问题感到震惊时,任何指针都将非常有帮助。