nsnotificationcenter

IOS/Objective-C: Get list of pending notifications from notification center

谁都会走 提交于 2019-12-12 04:09:26
问题 I am trying to get list of local notifications for my app that are in the notification center so I can display these in the app. I found this code in this SO answer but it is in Swift. Can anyone translate to Objective-C or suggest how to get the notifications that have fired but are pending in Objective-C? if #available(iOS 10.0, *) { UNUserNotificationCenter.current().getPendingNotificationRequests { (requests) in print("here are the iOS 10 notifs \(requests)") } } else { let requests =

Receiving a notification without loading the view

孤者浪人 提交于 2019-12-12 03:32:47
问题 As I explained in this question, I'm trying to pass data from a UISwitch in a TableView to another ViewController. However, I want the data to be passed when the Settings View (which contains the UISwitch) is dismissed. Following the third step of this great answer, I'm using UserDefaults to pass the data and trying to use NotificationCenter to update the UserDefaults values when dismissing the Settings View. To update when user defaults values change, you could have your Settings controller

NSNotificationCenter calling two times

喜你入骨 提交于 2019-12-12 03:08:12
问题 Below is what I have. MainViewController.m - (IBAction)sideMenuAction:(id)sender { NSLog(@"login==sideMenuAction"); [[NSNotificationCenter defaultCenter] postNotificationName:@"ShowMySideMenuNotification" object:self]; } NotificationListener.m -(void)viewDidLoad { [[NSNotificationCenter defaultCenter] removeObserver:self name:@"ShowMySideMenuNotification" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(adjustShowMenu) name:@"ShowMySideMenuNotification"

Mac Listen for event: Copy to Pasteboard

老子叫甜甜 提交于 2019-12-12 01:03:06
问题 I was reading NSPasteboard, then wanted to find.... I am trying to find the correct Notification method that listens to the copy event of data to the clipboard. Also I am trying to find file path of the data that is copied to the clipboard. Which would be a pasteboard object. If I copy text from a page in the browser, I am trying to find out how to grab the url address of the page the text was copied from. Any ideas? 回答1: No notification available. Devara Gudda is right. You request info from

Why can't I rely on NSNotificationCenter using AVFoundation to loop video?

余生颓废 提交于 2019-12-11 23:19:31
问题 I loop my video played with AVFoundation video with the help of NSNotificationCenter and playerItemDidReachEnd: AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil]; self.playerItem = [AVPlayerItem playerItemWithAsset:asset]; self.avPlayer = [AVPlayer playerWithPlayerItem:self.playerItem]; [self.avPlayer addObserver:self forKeyPath:@"status" options:0 context:AVMoviePlayerViewControllerStatusObservationContext]; [[NSNotificationCenter defaultCenter] addObserver:self selector:

Device Notification or value change, find it in other device

只愿长相守 提交于 2019-12-11 11:37:11
问题 I'm developing some application which should notify my current device values into other devices within certain area. Let say i'm having app, the same app installed in other 3 devices. When i change something in my device, that should be notified in other device. Like, i'm selecting one button, that button selection should be on other 3 devices too. Is it possible to do without web service and is there any specific frameworks there in iOS to do this task. Its kind of bluetooth searching

KeyboardWillShow only moves container UIView for certain UITextFields

风格不统一 提交于 2019-12-11 08:49:10
问题 I have a container UIView that contains a UICollectionView and a UIView, both of which have UITextFields in them. I used NSNotificationCenter to move the container view when the keyboard pops up. However, it only seems to work for the UICollectionView but not the sub UIView, as shown in the screenshots: works fine for the text fields in UICollectionView: but doesn't work for the text field in the UIView: EDIT: related code: override func viewWillAppear(animated: Bool) { super.viewWillAppear

Swift NSScrollView better NSViewBoundsDidChangeNotification observing?

丶灬走出姿态 提交于 2019-12-11 08:06:06
问题 Is there a better way to observe NSScrollView -> NSClipView frame/bounds change? This is Obj-C code translated to Swift: public override init(frame frameRect: NSRect) { self.contentView.postsFrameChangedNotifications = true; NSNotificationCenter.defaultCenter().addObserver( self, selector: "frameDidChange:", name: NSViewFrameDidChangeNotification, object: self.contentView) } deinit { NSNotificationCenter.defaultCenter().removeObserver( self, name: NSViewFrameDidChangeNotification, object:

Adding an observer to an NSString

假如想象 提交于 2019-12-11 07:07:58
问题 In my application delegate I have an NSString which can be modified by a class. What I want to do is to have another class observe this NSString and to react whenever this NSString is changed. Does anybody know how I can do this? 回答1: On the "other class" you must do something like: [MyAppDelegate addObserver:self forKeyPath:@"VARIABLE_NAME" options:NSKeyValueObservingOptionNew context:nil]; and implement - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:

Singleton service with many UIViews

[亡魂溺海] 提交于 2019-12-11 06:33:54
问题 Learning swift and just stuck with one issue. I'm trying to use delegates with singleton service. With delegate i want to update multiple views, but due to singleton implementation delegate keeps last UIView. So for example i have 3 UIViews with ids 1, 2, 3. When i'll do in init body self.myservice.delegate = self and will try to use specific delegate method ex. myServiceDidUpdate then in this delegate method accessing self.viewId always returning last id . I guess it's due to singleton