Reputation: 3078
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];
Upvotes: 0
Views: 750
Reputation: 11197
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.. :)
Upvotes: 1
Reputation: 2052
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
Upvotes: 2
Reputation: 7707
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.
Upvotes: 1