OS X

How to integrate Pushwoosh SDK into your OS X project

Download SDK Sample Project SDK API Docs

To integrate Pushwoosh into your application:

  1. Add Pushwoosh.framework to your project.

  2. In Info.plist add the Pushwoosh_APPID key with your Pushwoosh Application ID string value.

  3. Required code changes:

3.1. Add import definitions to your AppDelegate file.

Swift
Objective-C
Swift
import PushKit
import Pushwoosh
Objective-C
#import <Pushwoosh/Pushwoosh.h>

3.2. In the applicationDidFinishLaunching function add:

Swift
Objective-C
Swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
//lots of your initialization code
//-----------PUSHWOOSH PART-----------
NSUserNotificationCenter.default.delegate = Pushwoosh.sharedInstance()?.notificationCenterDelegateProxy
// set custom delegate for push handling, in our case - view controller
Pushwoosh.sharedInstance().delegate = self
// handling push on app start
Pushwoosh.sharedInstance().handlePushReceived(aNotification.userInfo)
// register for push notifications!
Pushwoosh.sharedInstance().registerForPushNotifications()
Objective-C
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
//lots of your initialization code
//-----------PUSHWOOSH PART-----------
[NSUserNotificationCenter defaultUserNotificationCenter].delegate = [Pushwoosh sharedInstance].notificationCenterDelegateProxy;
// set custom delegate for push handling, in our case - view controller
[Pushwoosh sharedInstance].delegate = self;
// handling push on app start
[[Pushwoosh sharedInstance] handlePushReceived:[aNotification userInfo]];
// register for push notifications!
[[Pushwoosh sharedInstance] registerForPushNotifications];
}

3.3. Add the following code to your UIApplicationDelegate (same file as above).

Swift
Objective-C
Swift
// system push notification registration success callback, delegate to PWMessagingDelegate
func application(_ application: NSApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Pushwoosh.sharedInstance()?.handlePushRegistration(deviceToken)
}
// system push notification registration error callback, delegate to PWMessagingDelegate
func application(_ application: NSApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
Pushwoosh.sharedInstance()?.handlePushRegistrationFailure(error)
}
Objective-C
// system push notification registration success callback, delegate to pushManager
- (void)application:(NSApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[[Pushwoosh sharedInstance] handlePushRegistration:deviceToken];
}
// system push notification registration error callback, delegate to pushManager
- (void)application:(NSApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
[[Pushwoosh sharedInstance] handlePushRegistrationFailure:error];
}

3.4. To handle push notifications add the following function to your UIApplicationDelegate (the same file as three steps above)

Swift
Objective-C
Swift
//this event is fired when the push gets received
func pushwoosh(_ pushwoosh: Pushwoosh!, onMessageReceived message: PWMessage!) {
print("onMessageReceived: \(String(describing: message.payload))")
}
//this event is fired when user taps the notification
func pushwoosh(_ pushwoosh: Pushwoosh!, onMessageOpened message: PWMessage!) {
print("onMessageOpened: \(String(describing: message.payload))")
}
Objective-C
//this event is fired when the push gets received
- (void)pushwoosh:(Pushwoosh *)pushwoosh onMessageReceived:(PWMessage *)message {
NSLog(@"onMessageReceived: %@", message.payload);
}
//this event is fired when user taps the notification
- (void)pushwoosh:(Pushwoosh *)pushwoosh onMessageOpened:(PWMessage *)message {
NSLog(@"onMessageOpened: %@", message.payload);
}

3.5 Add libz.dylib to the project:

  • go to Target section

  • open "Build Phases" tab

  • open "Link Binaries With Libraries"

  • click "+"

  • search "libz.dylib"

  • Click Add

Repeat for libstdc++.dylib library. Note that in Xcode 7 .dylib files have .tbd extension.

All done!