سؤال

Is this possible to post a NSNotification under console, when app's paused?


Why?

I need to test the reachability of a server in my app (I'm using Reachability.h).

So, I wonder if I could post notification by myself at random moments, by pausing the program and execute

[[NSNotificationCenter defaultCenter] postNotificationName:@"kReachabilityChangedNotification"
                                                        object:nil];

on the console, stopped on the main thread, to see if my ongoing downloads are well frozen.

I could :

  • unplug my ethernet wire,
  • turn the network off on my preference panel,
  • create a button which throws notifications,
  • post notification with timer,

but I wonder if a manual post would work.

As is, the command doesn't work on console, cause apparently receiver 'NSNotificationCenter' is a forward class and corresponding @interface may not exist.


Before I try to get around this :

  • Would that be good practice?
  • Someone already tried that?
  • Would I be sure it runs on the main thread?
هل كانت مفيدة؟

المحلول

You can just type in the lldb debugger when paused:

expr (void)[[NSNotificationCenter defaultCenter] postNotificationName:@"kReachabilityChangedNotification" object:nil]

As for your other questions:

Good practice? You could use the network link conditioner or set up your device to test various network conditions.

See Posting on the main thread

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top