MIDINetworkConnection导致崩溃错误
问题描述:
我遇到频繁崩溃,我认为这与检查MIDINetwork会话数量的这种方法有关。MIDINetworkConnection导致崩溃错误
- (NSString*) describeConnections {
NSMutableArray* connections = [NSMutableArray arrayWithCapacity:1000];
for (MIDINetworkConnection* connection in [[MIDINetworkSession defaultSession] connections]) {
[connections addObject:[[connection host] name]];
}
if ([connections count] > 0) {
return [connections componentsJoinedByString:@", "];
}
else
return @"(Not connected)";
}
当应用程序崩溃,停止上线
for (MIDINetworkConnection* connection in [[MIDINetworkSession defaultSession] connections])
我得到的错误是
Thread 1: EXC_BAD_ACCESS(code=EXC_1386_GPFLT)
在调试它显示
_impl _MIDINetworkConnectionImpl * NULL
我有试图通过检查M来防止崩溃在通过连接循环之前,IDINetworkSession为NULL,但没有奏效。有时当xcode崩溃时,它会停止在
int main(int argc, char *argv[])
{
@autoreleasepool {
int retVal = UIApplicationMain(argc, argv, nil, nil);
return retVal;
}
}
任何人都可以提供猜测发生了什么?
答
看起来连接包含NULL,在某些情况下系统释放连接。但是在集合中,它不能使用NULL作为元素,因此您应该检查连接或使用try catch来获取异常。
即使在检查连接不为空时,我仍然遇到应用程序崩溃。 – Youngin 2014-10-31 21:10:46