質問

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