Send NSDistributedNotification and get a response - cocoa

I created a firebreath plugin that sends a notification to a cocoa application. Is there any way to get a response from the application if the notification was recived successfully?

Assuming you can receive them in firebreath plugins, why don't you send an NSDistributedNotification back? I've used this mechanism to communicate an app with a background agent and it works perfectly.
[[NSDistributedNotificationCenter defaultCenter]
postNotificationName:<#ping-or-pong#>
object:<#sender-id#>
userInfo:nil
deliverImmediately:NO];
You can use <#sender-id#> (a string, for instance) to allow each part to skip its own notifications.

Related

Post notification using NSDistributionCenter in sandboxed apps

I am looking at ways on sending message from my main app to helper app. Its just a one way communication. I came accross XPC, unix sockets and NSDistributioncenter and found that posting notifications was the simplest one.
I am using postNotificationName:object: to send notifications.
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:#"aNote"
object:#"Hello"];
In helper app I have added observers in applicationDidFinishLaunching to receive notifications.
[[NSDistributedNotificationCenter defaultCenter] addObserver:self
selector:#selector(hello:)
name:#"aNote"
object:nil];
But it can only get notified if sandboxing is turned off. In the Apple docs it does say that userInfo must be nil if app is sandboxed but I am not using userInfo. I also tried with postNotificationName:object:userInfo: with userInfo nil but still it didnt work.
How can I get this to work in Sandboxed apps ?

Control the apple notification click when the initiator programm is not running

My product works as following:
My application opens notification
My application exits
Now, when the user clicks the notification, my application is opened again. I DONT WANT it. I want that if user clicks the notification - it will just disappear
I found there is a callback for that (and it works)
- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification
{
[center removeDeliveredNotification: notification];
}
but it works only when my application is running.
Is it possible to implement the behavior I want at all?
No it isn't possible to avoid having your application launched when a user touches your notification.
The application will always be launched in response to touching a notification and the UIApplicationDelegate method application:willFinishLaunchingWithOptions: will always be called when the application is not running.
Your app doesn't have to action on the notification, but it will be launched.

How to use Background agent to send toast notification?

I am working on windows development & I am displaying the items on the emulator by using a web service.
Now I want to send a toast notification when an item added to the service. Already I worked with push notifications. But It’s generating push channel URL when app is initialized.
I don’t want to use this channel URL. So I tried Background Agent & Shell Toast to send the notification. Its working fine for static data. How can I add dynamic data to back ground agent which is coming from web service?
One more thing is, there are two things like PeriodicTask & ResourceIntensiveTask. How can I use this to send a toast notification by using Background Agent?
You can refer to this Tutorial From Nokia
http://developer.nokia.com/community/wiki/How_to_create_simple_Background_Agent_in_Windows_Phone
and this from CodeProject
http://www.codeproject.com/Articles/656654/Windows-Phone-Background-Agent-Part-Periodic-T

Subscribe to Spotify events

Does anyone know of a way to subscribe to events in the Spotify application? To subscribe to iTunes events, you would just add an observer to the notification center like this:
[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:#selector(changedTrack:) name:#"com.apple.iTunes.playerInfo" object:nil];
Thereby all events will be send in an NSNotification to changedTrack:.
I can't seem to find a similar (or any way) to do this for Spotify but I know there are applications doing this, for example applications showing the song currently being played.
Spotify's NSDistributedNotification name is com.spotify.client.PlaybackStateChanged.
Subscribe to that using NSDistributedNotificationCenter and you'll get a notification very similar to iTunes'.

Windows Phone 7 - Is it possible to add additional key/values to push notifications messages

I'm testing out Windows Phone 7.5 push notifications. I have got the 3 different push types working fine (Toast, Tile and Raw) and am able to send messages from unit tests and a web application without any problems and receive them in my WP application. I want the ability to add extra properties to the push notification and the Raw push type does this perfectly for me and I can add custom key/value pairs or anything else to the push message and extract it on the phone app. I have just found out however that it only works if the application is running and my unit tests fail (suppressed notification status is received in unit test) when the phone application is not running (checked documentation which confirms this too). Is there anyway to add extra properties (key/values) to toast or tile messages or some way I can use raw in another way ? Toast notifications seem limited to a title property and an actual message property but I need to add additional data.
Just wondering if anyone had any suggestions / workarounds ?
The general practice I use is to initially send a raw notification to the device with phone-usable data embedded in the message. If my application is currently running then I can process the contents of the raw message and immediately make use of it on the phone. However if the application is not currently running on the phone you will receive notification from the push servers that the message could not be delievered. If I receive this response I send out a Toast / Tile notification.
With Toast notifications the only parametrisation you have access to is the URI that will launch the application. This is specified with the wp:param node of the message. Eg.
<wp:Notification xmlns:wp="WPNotification">
<wp:Toast>
<wp:Text1>Toast Title</wp:Text1>
<wp:Text2>Toast sub title</wp:Text2>
<wp:Param>/MainPage.xaml?LaunchedFrom=A%20Toast%20Notification</wp:Param>
</wp:Toast>
</wp:Notification>
If the user taps on this toast notification your application will launch and navigate to MainPage.xaml. You can access the querystring passed in via the NavigationContext.QueryString.
Note: The wp:Param node can only be sent to Mango (and up) devices. Additionally the entire contents must be less than 256 characters or you'll receive a PushErrorTypeMessageBadContent error. (Thanks to Ritch Melton for pointing this out). More info available from the Sending Push Notifications for Windows Phone page on MSDN.
As you've discovered, the Microsoft Push Notification Service is very strict in what types of messages you can send and receive. The intent of these push notifications is to provide simple push updates and not large amounts of data. The flexible Raw type seems like it would fit the bill until you discover that:
You can use a raw notification to send information to your application. If your application is not currently running, the raw notification is discarded on the Microsoft Push Notification Service and is not delivered to the device.
However, if you send a toast notification to your application, when the user clicks on the toast the application is started. When your application starts, you should check a service and retrieve the data you are trying to send from a web-service or other remote mechanism.

Resources