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'.
Related
Is there one place to see all of the events for amp-story, events in the pipeline, and events that are never going to go live?
sample topics
clipboard events
drag events
mouse events
keyboard events
window event attributes
form events
media events
miscellaneous events such as ontoggle, which fires in HTML5 when the user opens or closes the element
I don't think such a list exists, but there are not currently any events that publishers can hook into, nor are there any pending.
You can always file a feature request with any specific use cases you might have.
In doing some testing on the iOS 11 preview, I've noticed that when I get push notifications while my app is foregrounded the OS displays the system notification that you normally only see when your app is not active.
I didn't see anything announced as having been changed, or any new APIs to change this behavior one way or another. Does anyone know or have links to documentation stating if this is intended, a bug, temporary, or what?
There's an option for showing Push Notifications in the foreground in UserNotification framework.
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
Quoting the comment from the Framework:
The method will be called on the delegate only if the application is in the foreground. If the method is not implemented or the handler is not called in a timely manner then the notification will not be presented. The application can choose to have the notification presented as a sound, badge, alert and/or in the notification list. This decision should be based on whether the information in the notification is otherwise visible to the user.
This could be the place to start looking for the answer.
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 ?
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.
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.