I Quellcode haben, wie folgend:Beenden app aufgrund nicht abgefangene Ausnahme ‚NSInternalInconsistencyException‘, Grund: ‚beginnen kann nicht in der Mitte einer Iteration Iterieren‘
+ (NSDictionary *)incrementalUpdateTask
{
__block NSDictionary *result = nil;
__block BOOL isFinish = NO;
[EQPlatformManager getIncrementTaskWithSuccess:^(NSArray *deletedList, NSArray *updateList) {
result = @{@"delete":deletedList, @"update":updateList};
isFinish = YES;
} failed:^(NSError *error) {
isFinish = YES;
}];
while (!isFinish) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
beforeDate:[NSDate distantFuture]];
}
return result;
}
Dieser Code-Segment Ausnahme führt, wie folgend :
0 CoreFoundation ___exceptionPreprocess + 124
1 libobjc.A.dylib objc_exception_throw + 56
2 CoreFoundation +[NSException raise:format:]
3 Foundation -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 88
4 UIKit __prepareForCAFlush + 500
5 UIKit __beforeCACommitHandler + 24
6 CoreFoundation ___CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
7 CoreFoundation ___CFRunLoopDoObservers + 372
8 CoreFoundation CFRunLoopRunSpecific + 476
9 Foundation -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 304
10 MyAPPName +[EQUtil incrementalUpdateTask] (EQUtil.m:2317)
11 MyAPPName -[EQMainTaskViewController appDidBecomeActive] (EQMainTaskViewController.m:331)
Diese Ausnahme tritt gelegentlich auf und ist sehr schwierig zu reproduzieren. Kann mir jemand helfen?
Thank you very much. Die Methode 'incrementalUpdateTask' wird im Handler von UIApplicationDidBecomeActiveNotification ausgeführt, was bedeutet, dass sie im Hauptthread ausgeführt wird. Eigentlich erwarte ich * while loop * execute ** bevor ** der asynchrone Code beendet ist. Dies bedeutet, dass der Haupt-Thread blockiert wird, bis der asynchrone Code beendet ist. Das ist genau das, was ich will. – Emalwb
Sie sollten niemals einen Thread absichtlich blockieren. Was auch immer Sie versuchen, Ihre Idee zu tun, ist falsch. Es wird immer eine bessere Lösung geben. – Gruntcakes