The community forums are in BETA and closed to the public.

OS X notifications

I'm currently using pubnub's mobile push to send push notifications to our app on ios and android.

Would it be possible to utilize pubnub to also send out osx desktop notifications? (supported in mavericks and yosemite)

Hey there, as far as I understand, you can use APNS for OS X notifications (not the Safari browser one) but still have to set up the certificate for it, which means you have to have a Mac App with APNS certificate, provisioning profile, etc. You do things similarly, meaning you have to launch the application and send/register the Mac as a deviceToken, just like iOS. I know that OS X notifications aren't quite as robust as iOS. I've never done it myself, but I have read about it :).

But I believe you can send a notification to both iOS and OS X at the same time...

Ah, I didn't answer your question, so, since PubNub forwards messages with APNS content to Apple's APNS system, which is a single system for both iOS and OS X, the answer is Yes, it can be used for both iOS and OSX.

OSX Push API with APNs Apple Push Notification Service

You can pick two routes depending on your deployment platform. Safari or Native Cocoa?

Pushing Notifications in Safari

You send push notifications to clients in the same way that iOS and OS X apps push notifications to APNs. As a push notification provider, you communicate with APNs over a binary interface. This a high-speed, high-capacity interface uses a streaming TCP socket design with binary content. The binary interface is asynchronous.

Safari Push Notifications

The binary interface of the production environment is available through which PubNub manages for you hurray! A JSON dictionary like the one in below produces a notification. The JSON object must strictly conform to RFC 4627.

A JSON dictionary showing a sample notification payload:

pubnub.publish({ channel : "notify-channel", message : {
    "aps": {
        "alert": {
            "title": "Flight A998 Now Boarding",
            "body": "Boarding has begun for Flight A998.",
            "action": "View"
        "url-args": ["boarding", "A998"]
} });

The resulting push notification

Safari Push Notification Example

The outermost dictionary, which is identified by the aps key, should contain another dictionary named alert. The alert dictionary may contain only the keys listed in the example above.

Native Cocoa Push Notifications

[center scheduleNotification:notification];

Which you can invoke upon receiving a message via PubNub Objective-C SDK as follows:

// Define a Push channel
PNChannel *myChannel = [PNChannel channelWithName:@"notify-channel"];

// Receive Messages Sent to Me!
[PubNub subscribeOnChannel:myChannel];

//(In AppDelegate.m, define didReceiveMessage delegate method:)
- (void)pubnubClient:(PubNub *)client didReceiveMessage:(PNMessage *)message {
    NSUserNotification *notification = [[NSUserNotification alloc] init];
    [notification setTitle:@"Hello World"];
    [notification setInformativeText:@"Hello world message"];
    [notification setDeliveryDate:[NSDate dateWithTimeInterval:20 sinceDate:[NSDate date]]];
    [notification setSoundName:NSUserNotificationDefaultSoundName];
    NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
    [center scheduleNotification:notification];

Comments to this discussion are now closed!