nsnotificationcenter

Mac Mountain Lion send notification from CLI app

天涯浪子 提交于 2019-11-27 19:30:39
How can I send a notification to the notification center from a command line app? My attemps so far compile and run, but don't succeed in notifying me. Example #import <Cocoa/Cocoa.h> int main(int argc, const char * argv[]) { NSLog(@"Running notifications"); NSUserNotification *note = [[NSUserNotification alloc] init]; [note setTitle:@"Test"]; [note setInformativeText:@"Woot"]; NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter]; [center scheduleNotification: note]; return 0; } I then compile like: clang -framework cocoa /tmp/Notes.m and I get 2012-07-29

thumbnailImageAtTime: now deprecated - What's the alternative?

别说谁变了你拦得住时间么 提交于 2019-11-27 18:23:29
Until iOS7 update I was using... UIImage *image = [moviePlayer thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame]; ...with great success, so that my app could show a still of the video that the user had just taken. I understand this method, as of iOS7 has now deprecated and I need an alternative. I see there's a method of - (void)requestThumbnailImagesAtTimes:(NSArray *)playbackTimes timeOption:(MPMovieTimeOption)option though how do I return the image from it so I can place it within the videoReview button image? Thanks in advance, Jim. ****Edited question, after trying

NSNotificationCenter vs delegation - which is faster?

为君一笑 提交于 2019-11-27 17:44:43
问题 I have read a lot about the pros and cons of each , and i know delegates are usually for one listener, and notifications are for many. The question is about performance. I have read this : NSNotificationCenter vs delegation( using protocols )? I am sending audio signals from mic, to another class by notification . i know that here i should use the delegate BUT my question is : does delegates will be faster ? because i can see i have some frame rate issue(decreased), and i would like to know

How can I listen for all notifications sent to the iOS NSNotificationCenter's defaultCenter?

纵饮孤独 提交于 2019-11-27 17:23:32
I want to listen to all notifications dispatched to the defaultCenter. Both public and private. Does anyone know how I can do this? Sam 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:" "

How do you create custom notifications in Swift 3?

人盡茶涼 提交于 2019-11-27 17:19:10
In Objective-C, a custom notification is just a plain NSString, but it's not obvious in the WWDC version of Swift 3 just what it should be. You could also use a protocol for this protocol NotificationName { var name: Notification.Name { get } } extension RawRepresentable where RawValue == String, Self: NotificationName { var name: Notification.Name { get { return Notification.Name(self.rawValue) } } } And then define your notification names as an enum anywhere you want. For example: class MyClass { enum Notifications: String, NotificationName { case myNotification } } And use it like

Why is my NSNotification its observer called multiple times?

大城市里の小女人 提交于 2019-11-27 14:27:46
问题 Within an App I make use of several viewcontrollers. On one viewcontroller an observer is initialized as follows: [[NSNotificationCenter defaultCenter] removeObserver:self name:@"MyNotification" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMethod:) name:@"MyNotification" object:nil]; Even when removing the NSNotification before initializing the number of executions of myMethod: is being summed up by the amount of repeated views on the respective

pausing spritekit game on app launch / exit .. iOS8

老子叫甜甜 提交于 2019-11-27 14:03:38
问题 I've read everything I could find on this topic and still cant figure out my issue. I have tried pausing my game in every area of appdelegate func applicationWillResignActive(application: UIApplication!) { NSNotificationCenter.defaultCenter().postNotificationName("pauseGameScene", object: self) } func applicationDidEnterBackground(application: UIApplication!) { NSNotificationCenter.defaultCenter().postNotificationName("pauseGameScene", object: self) } func applicationWillEnterForeground

OSX Notification Center Icon

瘦欲@ 提交于 2019-11-27 13:34:03
I'm using OSX's Notification Center APIs for the first time and can't seem to figure out how to make my app's icon to show up in the Notification badge. The default "your app doesn't have an icon" icon keeps showing up: Here's what I've done so far I have created an icns file that includes 512, 256, 128, 32 & 16px versions dragged the icon into the "App Icon" section of the target's summary I made to sure to check the box to copy the icon into the project the plist's "Icon file" section references the correct icon name (minus the .icns) part Any ideas? The icon doesn't show up when I run the

Getting state for system wide notifications in iOS and OS X

时光总嘲笑我的痴心妄想 提交于 2019-11-27 13:32:49
问题 I am trying to write a code which will handle turning on/off screen on iOS (You can take a look at this question where similar problem is discussed). I included OSX tag for this question, because OSX has the same system wide notification facility. And the problem described below is inherit to the notifications facility (vs to iOS or OSX). There is well known method of registering for system wide notification com.apple.springboard.hasBlankedScreen to receive notifications when the screen is

How to post and receive an NSNotifications (Objective C) | Notifications (in Swift)?

巧了我就是萌 提交于 2019-11-27 13:11:21
Is there an easy-to-grock pattern how to send a NSNotification (Objective C) | Notification (in Swift) and how to receive one? Code snippet? The docs write like 150 pages on the topic. Would like to see a quick example. Send a notification: [[NSNotificationCenter defaultCenter] postNotificationName:@"MyCacheUpdatedNotification" object:self]; Receive it: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cacheUpdated:) name:@"MyCacheUpdatedNotification" object:nil]; Act on it: - (void)cacheUpdated:(NSNotification *)notification { [self load]; } And dispose of it: [