terryworona / TWMessageBarManager

An iOS manager for presenting system-wide notifications via a dropdown message bar.
MIT License
1.77k stars 191 forks source link

callback block not executed #96

Closed dfeng99 closed 7 years ago

dfeng99 commented 7 years ago

The callback block is not called when tapped on the message. The code is like this:

[[TWMessageBarManager sharedInstance] showMessageWithTitle:title description:body type:TWMessageBarMessageTypeSuccess duration:5.0 callback:^{ NSLog(@"Message bar tapped!"); FREDispatchStatusEventAsync(myCtx, (uint8_t)"MSG_BAR_IS_TAPPED", (uint8_t)[action UTF8String]); }];

terryworona commented 7 years ago

Are you calling this from the main thread?

If not, make sure you wrap the call in a dispatch_async:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
   // your code here
});

I tested your code with the demo app and it worked fine:

screen shot 2017-02-19 at 9 13 34 pm

dfeng99 commented 7 years ago

Yes, thanks! I wrap it in dispatch_async and it works now! Thank you!

dfeng99 commented 7 years ago

Can you explain a little? Since the code in the block is already an async call. I won't head to this solution without your help.

dfeng99 commented 7 years ago

Well, I only got one time lucky, it's weird! most of the time, when I click on the message, it just simply dismissed without dispatch the event in the block.

dfeng99 commented 7 years ago

I finally resolve the issue by moving the code inside the block to a local method and call this method within the block.

terryworona commented 7 years ago

Great!