문제

Can someone explain to me what this error message is saying?

Assertion failed: ([NSThread isMainThread]), function -[AFContextManager addContextProvider:], file /SourceCache/MobileAssistantFramework/MobileAssistantFramework-651.49/AFContextManager.m, line 113.

This only happens about 1/8 of running my application.

I believe the last line of code in this snippet is causing it.

HUD = [[MBProgressHUD alloc]initWithView:self.view];
HUD.labelText = @"Scanning..";
[self.view addSubview:HUD];

[HUD showWhileExecuting:@selector(scanWithImage:) onTarget:self withObject:image animated:YES];
도움이 되었습니까?

해결책 2

Try this:

HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
HUD.labelText = @"Scanning..";
[HUD showWhileExecuting:@selector(scanWithImage:) onTarget:self withObject:image animated:YES];

Hope this helps.. :)

다른 팁

Force it to run on the main thread. Like this

dispatch_sync(dispatch_get_main_queue(), ^{
    HUD = [[MBProgressHUD alloc]initWithView:self.view];
    HUD.labelText = @"Scanning..";
    [self.view addSubview:HUD];

    [HUD showWhileExecuting:@selector(scanWithImage:) onTarget:self withObject:image animated:YES];
});

This assumes that the UI is not blocking while executing the above code and that you ABSOLUTELY want it to be synchronous. Else its very safe to use dispatch_async

The addContextProvider: method is asserting that it is being run on the main thread. Likely the issue is that a method you must call from the main thread is being called from a background thread.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top