nsnotificationcenter
iOS NSNotificationCenter to check whether the app came from background to foreground
Have you tried UIApplicationWillEnterForegroundNotification? The app also posts a UIApplicationWillEnterForegroundNotification notification shortly before calling applicationWillEnterForeground: to give interested objects a chance to respond to the transition. Subscribe to notification: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(yourUpdateMethodGoesHere:) name:UIApplicationWillEnterForegroundNotification object:nil]; Implement a code, that need to be called: – (void) yourUpdateMethodGoesHere:(NSNotification *) note { // code } Don’t forget to … Read more
NSNotificationCenter : list of observers?
(iOS 9, Swift 3) If you want to find out which observers are currently registered in NotificationCenter, break and print its debug description: (lldb) e print(NotificationCenter.default.debugDescription) Each line of the output will contain (Notification) Name, Object, Observer, Options. Multiple calls to NotificationCenter.default.addObserver with some NSNotification.Name will result in multiple entries in this list. NB. while … Read more
How to pass a NSDictionary with postNotificationName:object:
The first NSLog works fine displaying the contents of the dictionary. The second log throws the following exception… The program tries to trick you, it just looks like it is your dictionary because your dictionary is inside the notification. From the exception you can see that your object actually is from a class named NSConcreteNotification. … Read more
Are NSNotificationCenter events received synchronously or asynchronously?
As stated in the documentation for NSNotificationCenter NSNotificationCenter Class Reference notifications are posted synchronously. A notification center delivers notifications to observers synchronously. In other words, the postNotification: methods do not return until all observers have received and processed the notification. To send notifications asynchronously use NSNotificationQueue. In a multithreaded application, notifications are always delivered in … Read more
Detecting Network Connectivity Changes using Reachability, NSNotification and Network Link Conditioner in Swift
You must create a Reachability object before you can receive notifications from it. Also, be sure to call the startNotifier() method on the Reachability object you create. This would be an example of how to do so inside of your application delegate: class AppDelegate: UIResponder, UIApplicationDelegate { private var reachability:Reachability!; func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: … Read more
How can I listen for all notifications sent to the iOS NSNotificationCenter’s defaultCenter?
Use NSNotificationCenter’s addObserverForName:object:queue:usingBlock: OR addObserver:selector:name:object: method and pass nil for the name and object. Example The following code should do the job: – (void)dumpNotifications { NSNotificationCenter *notifyCenter = [NSNotificationCenter defaultCenter]; [notifyCenter addObserverForName:nil object:nil queue:nil usingBlock:^(NSNotification *notification){ // Explore notification NSLog(@”Notification found with:” “\r\n name: %@” “\r\n object: %@” “\r\n userInfo: %@”, [notification name], [notification object], … Read more
How to receive NSNotifications from UIWebView embedded YouTube video playback
There are no documented notifications sent by the UIWebView embedded movie player. In fact, the closed implementation used within the UIWebView does differ from the public MPMoviePlayerController in many aspects (e.g. DRM). The most important classes used for playing video content within that UIWebView are called MPAVController and UIMoviePlayerController. The latter one makes the player … Read more
How to set addObserver in SwiftUI?
The accepted answer may work but is not really how you’re supposed to do this. In SwiftUI you don’t need to add an observer in that way. You add a publisher and it still can listen to NSNotification events triggered from non-SwiftUI parts of the app and without needing combine. Here as an example, a … Read more