nsnotifications

Remove Observer when using addObserverForName:usingBlock

巧了我就是萌 提交于 2019-12-22 01:42:38
问题 I have the following code that adds an observer in the loading of the view. - (void)viewDidLoad { [super viewDidLoad]; [[NSNotificationCenter defaultCenter] addObserverForName:@"com.app.livedata.jsonupdated" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { NSLog(@"JSONUPDATED"); }]; } And this fires fine. However when the view is unloaded and I confirm the dealloc is called the Notification is still firing. There doesn't seem to be a method for deactivating

watchkit , iOS sending data between watch and iphone

瘦欲@ 提交于 2019-12-22 01:27:59
问题 I want to create one button in watch and while tapping on watch start one process to my ios app. How can I send the data between 2 devices -(void)viewWillAppear:(BOOL)animated { [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(sayHello:) name: @"sayHelloNotification" object: nil]; } plus [[NSNotificationCenter defaultCenter] postNotificationName: @"sayHelloNotification" object: nil]; in my button watch but it doesn't work 回答1: AFAIK, you can not share data directly,

When to unsubscribe from a NSNotification in a UIView

老子叫甜甜 提交于 2019-12-20 09:19:40
问题 I am using the following NSNotifications within a UIView so that the view can be notified when a UIKeyboard appears and adjust its position (frame) on screen: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil]; The two notifications above are being subscribed to

Event on view displayed change (Youtube MPMoviePlayerViewController)

半世苍凉 提交于 2019-12-19 09:26:27
问题 I would like to know when the YouTube MPMoviePlayerViewController appear (programmatically) after have clicked on the UIWebView which permit to play the video in iOS, to get and to have control on this view. Because I want to get information from the player like the current playback time, loading time... like in a regular MPMoviePlayerViewController. Thanks 回答1: You will, under no circumstances receive any notifications from the WebView embedded player. Update: This is not entirely true.

Does NSFetchedResultsController Observe All Changes to Persistent Store?

╄→尐↘猪︶ㄣ 提交于 2019-12-19 06:16:14
问题 My program does work like link below: Update results of NSFetchedResultsController without a new fetch show result of NSFetchedResultsController to UITableView get new object from web service and store it to core data (in same view controller, with RestKit) update table view with notification of NSFetchedResultsController delegate The implementation of NSFetchedResultsControllerDelegate is copied from Apple's Core Data project and my predicated is: [NSPredicate predicateWithFormat:@"isMyTest

Global Mouse Moved Events in Cocoa

半城伤御伤魂 提交于 2019-12-18 10:56:20
问题 Is there a way to register for global mouse moved events in Cocoa? I was able to register for the events using Carbon's InstallEventHandler() , but would prefer a Cocoa equivalent. I have looked for NSNotificationCenter events, but there doesn't seem to be any public event names (are there private ones?) Alternatively, is there a way to use NSTrackingArea for views with a clearColor background? The app is Snow Leopard only. 回答1: In SnowLeopard there is a new class method on NSEvent which does

How do I access remote push notification data on applicationDidBecomeActive?

≯℡__Kan透↙ 提交于 2019-12-18 05:57:08
问题 When receiving a remote push notification as the application is in the background, the app enters applicationDidBecomeActive. From there, how can I access the NSDictionary of data from the notification? 回答1: The notification data is delivered to your app in application:didReceiveRemoteNotification: . If you want to process it in applicationDidBecomeActive: you should store it in application:didReceiveRemoteNotification: and read it again in applicationDidBecomeActive . 回答2: Swift version: var

When to use a colon with a @selector

对着背影说爱祢 提交于 2019-12-17 10:52:21
问题 Just getting going with iPhone development and Objective-C . Yesterday I was trying to addObserver for a notification in a view of mine, and I kept getting this error: unrecognized selector sent to instance I tracked it down to the fact that I needed to include the trailing colon to my selector argument: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nameOfMySelector:) name:@"BBLocationServicesAreDisabled" object:nil]; Today, I thought I was clever because when

Where to remove observer for NSNotification in Swift?

随声附和 提交于 2019-12-17 08:53:30
问题 Where should I remove the observer for NSNotification in Swift, since viewDidUnload and dealloc() are unavailable? 回答1: Use below method which functions same as dealloc . deinit { // Release all resources // perform the deinitialization } A deinitializer is called immediately before a class instance is deallocated. You write deinitializers with the deinit keyword, similar to how intializers are written with the init keyword. Deinitializers are only available on class types. Swift

Warning for iOS/iPhone users about duplicate NSNotification observations

江枫思渺然 提交于 2019-12-13 12:23:42
问题 This isn't a question so much as a warning to others to save them some time. NSNotificationCenter on iOS 3/iPhone OS 3 (I'm assuming also Mac OS X and iOS 4) has the following behavior: If you register yourself multiple times for the exact specific notification, NSNotificationCenter will NOT recognize the redundancy and instead will fire off as many notifications to you as you've registered an observation for. This is almost never the behavior you want to see and is almost always accidental.