In the command line tool version (your first 10 line code sample), is that the whole of the main() function? In that case, my guess is that your process exits before the notification is executed. In the iOS version, if it takes time for the app to quit, there may be time for the notification to execute before termination.
You seems right and i think the different maybe related to Runloop:
When I add
to bottom of line 11.The notify revoked in Main Thread correctly.
I read the libdispatch ,this function reboot the root queue. In the first case,i think the main queue was disposed after dispatch_notify.... so program can't find target queue(Main queue) to execute the NSLog Block when notify invoked.
With the runloop in iOS Application the main queue will exist all the time