nsnotifications

How to migrate NSWorkspace notifications to Swift 4?

半世苍凉 提交于 2019-12-06 04:07:48
In Swift 3 I registered for sleep and wake notifications with this code: let notificationCenter = NSWorkspace.shared.notificationCenter notificationCenter.addObserver(self, selector: #selector(AppDelegate.sleepListener), name: NSNotification.Name.NSWorkspaceWillSleep, object: nil) notificationCenter.addObserver(self, selector: #selector(AppDelegate.wakeUpListener), name: NSNotification.Name.NSWorkspaceDidWake, object: nil) but after migrating to Swift 4, I get this error after applying the suggested fixes: Type 'NSNotification.Name' has no member 'NSWorkspace' How do I do this in Swift 4? To

How To set Custom repeat interval For Nslocal Notification…?

断了今生、忘了曾经 提交于 2019-12-05 08:11:43
i am New to iphone Development .I Am Trying To Use NslocalNotification In My Project I Need To Give Remeinder For Every 2Hours or For Every Two Days Or For Every Two Months Etc..Currently I am Using NslocalNotification Repeat Interval .But Its Working For Only Every Minute For Every Hour using Nscalender .... NSString *InterVal=[freQuencyArr objectAtIndex:index-2]; NSString *InterValType=[freQuencyArr objectAtIndex:index-1]; if(![InterVal isEqualToString:@"Every"]) { result=[InterVal intValue]; }else result=1; if([InterValType isEqualToString:@"Day"]){ notification.repeatInterval=

If add an observer for a notification in the AppDelegate, do I need to bother removing it?

陌路散爱 提交于 2019-12-05 07:57:58
In the AppDelegate's didFinishLaunchingWithOptions : [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contextChanged:) name:NSManagedObjectContextDidSaveNotification object:nil]; This is so I can merge changes to the data from other threads. Question: Do I need to bother removing this listener in applicationWillResignActive or applicationWillTerminate ? It doesn't seem like there's a point. I guess I'm asking if it's normal to have listeners like this in the main loop that never get removed. You can never remove it, but if your app receive a notification (it won't

How NSNotification works

随声附和 提交于 2019-12-05 07:31:06
I understand what in Notification, poster and observer. But I am quite unable to understand how our app or OS understands and sends the flag/notification to the observer-class? What is the mechanism behind this? Your answer and help will be appreciated a lot. Thanks ID. Imagine the Notification Center as a dictionary which has keys of the notification names and values of the list of observers (and their specified action methods). When a notification is posted, the list of observers for that notification name is obtained and iterated. Each observer has its action method called with the

Is there a notification on iOS if a UIAlertView is shown?

China☆狼群 提交于 2019-12-05 07:12:30
Wondering if there is a notification available if a UIAlertView pops up? Background: my app asks the user for a PIN after a period of inactivity but I would like to prevent it if an alert is on screen. I don't want to go through my code and find all alerts and disable the PIN checker, instead a notification would be awesome. Any hope with NSNotification ? Krumelur Just found the answer. It is hidden in here: Can I get message when I show UIAlertView If you listen to the " UIWindowDidBecomeVisibleNotification " notification, it will also fire for your own alerts, not only for system alerts. For

Network Connection NSNotification for OSX?

℡╲_俬逩灬. 提交于 2019-12-05 06:05:40
问题 I simply need to have a notification post when a valid IP address is assigned. I have tried polling via SCReachability, but that seems to be inefficient. Any suggestions? This seems like it should be simple, but I've been struggling for several hours to get anything working. 回答1: I know this is a bit old but the selected answer is not ideal. The SCReachability API can be used to know when a particular host is reachable. If all you want to know is when a valid IP address is assigned (rather

Class method and instance method with the same name in Objective-C

十年热恋 提交于 2019-12-05 04:47:43
I have a solution for a notification problem which works well, but I'm afraid might be a bad idea. I have a notification that needs to be handled by each instance of a class and by the class itself. To handle this, I'm registering for a notification by both the class and instances of the class. Because it's the exact same notification, I've named the class and instance method the same. This follows the standard we've set for how notification handlers are named. Is this a bad idea? Is there some hidden got'ca that I'm missing. Will I be confusing the heck out of future developers? + (void

Best practices for passing data between processes in Cocoa

我只是一个虾纸丫 提交于 2019-12-05 01:23:25
问题 I am in the middle of solving a problem which requires me to do the following in my 64-bit Cocoa application: Spawn a 32-bit Cocoa helper tool (command line tool) from within my application. This helper will open a file (a quicktime movie to be precise) and access information about that file using 32-bit only APIs (Quicktime-C APIs) The data gathered from the 32-bit process needs to be passed back to the 64-bit application. The 64-bit app should wait until the 32-bit process completes before

Warning for iOS/iPhone users about duplicate NSNotification observations

对着背影说爱祢 提交于 2019-12-04 22:29:01
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. Example: I want my view controller to receive notifications from a singleton network object when new

Notifications are not getting in iOS 9.2

旧街凉风 提交于 2019-12-04 20:55:10
Notifications are not getting after upgrade to iOS9.2 but up to iOS9.1 there is no such type of issue. But I didn't understand where was the problem. Is it iOS9.2 problem ? Can anyone help me out from this. Thanks in advance. iPhone 4s seems to be having little discrepancies in ios 9.2 like notification icons are coming but no vibrations or sound alerts are there. Are you using a iPhone 4s? 来源: https://stackoverflow.com/questions/34528733/notifications-are-not-getting-in-ios-9-2