OS X
How to integrate Pushwoosh SDK into your OS X project

Linking Pushwoosh.framework

Add Pushwoosh.framework to your project via a dependency manager by putting the following lines in your podfile or cartfile:
Podfile
Cartfile
1
platform :osx, '10.7'
2
3
target 'MyApp' do
4
pod 'Pushwoosh_mac'
5
end
Copied!
1
github "Pushwoosh/pushwoosh-mac-sdk"
Copied!
Alternatively, you can simply drag and drop the framework into Link Binaries With Libraries in your project's Build Phases.

Adding libraries

In Build Phases tab of your project, open Link Binaries With Libraries and click on Add items ("+" button). Search for and add libz.tbd and libc++.tbd libraries to your project:

Linking the app with Pushwoosh Control Panel

In your Info.plist, add a string type key Pushwoosh_APPID with your Pushwoosh Application Code as value.

Modifying the AppDelegate

Add the following code to your AppDelegate:
Swift
Objective-C
1
import PushKit
2
import Pushwoosh
3
4
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
5
6
//lots of your initialization code
7
8
//-----------PUSHWOOSH PART-----------
9
10
NSUserNotificationCenter.default.delegate = Pushwoosh.sharedInstance()?.notificationCenterDelegateProxy
11
12
// set custom delegate for push handling, in our case - view controller
13
Pushwoosh.sharedInstance().delegate = self
14
15
// handling push on app start
16
Pushwoosh.sharedInstance().handlePushReceived(aNotification.userInfo)
17
18
// register for push notifications!
19
Pushwoosh.sharedInstance().registerForPushNotifications()
Copied!
1
#import <Pushwoosh/Pushwoosh.h>
2
3
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
4
{
5
//lots of your initialization code
6
7
//-----------PUSHWOOSH PART-----------
8
9
[NSUserNotificationCenter defaultUserNotificationCenter].delegate = [Pushwoosh sharedInstance].notificationCenterDelegateProxy;
10
11
// set custom delegate for push handling, in our case - view controller
12
[Pushwoosh sharedInstance].delegate = self;
13
14
// handling push on app start
15
[[Pushwoosh sharedInstance] handlePushReceived:[aNotification userInfo]];
16
17
// register for push notifications!
18
[[Pushwoosh sharedInstance] registerForPushNotifications];
19
}
Copied!
Add the following code to your UIApplicationDelegate (same file as above).
Swift
Objective-C
1
// system push notification registration success callback, delegate to PWMessagingDelegate
2
func application(_ application: NSApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
3
Pushwoosh.sharedInstance()?.handlePushRegistration(deviceToken)
4
}
5
6
// system push notification registration error callback, delegate to PWMessagingDelegate
7
func application(_ application: NSApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
8
Pushwoosh.sharedInstance()?.handlePushRegistrationFailure(error)
9
}
Copied!
1
// system push notification registration success callback, delegate to pushManager
2
- (void)application:(NSApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
3
[[Pushwoosh sharedInstance] handlePushRegistration:deviceToken];
4
}
5
6
// system push notification registration error callback, delegate to pushManager
7
- (void)application:(NSApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
8
[[Pushwoosh sharedInstance] handlePushRegistrationFailure:error];
9
}
Copied!
To handle push notifications, add the following function to your UIApplicationDelegate (the same file as three steps above):
Swift
Objective-C
1
//this event is fired when the push gets received
2
func pushwoosh(_ pushwoosh: Pushwoosh!, onMessageReceived message: PWMessage!) {
3
print("onMessageReceived: \(String(describing: message.payload))")
4
}
5
6
//this event is fired when user taps the notification
7
func pushwoosh(_ pushwoosh: Pushwoosh!, onMessageOpened message: PWMessage!) {
8
print("onMessageOpened: \(String(describing: message.payload))")
9
}
Copied!
1
//this event is fired when the push gets received
2
- (void)pushwoosh:(Pushwoosh *)pushwoosh onMessageReceived:(PWMessage *)message {
3
NSLog(@"onMessageReceived: %@", message.payload);
4
}
5
6
//this event is fired when user taps the notification
7
- (void)pushwoosh:(Pushwoosh *)pushwoosh onMessageOpened:(PWMessage *)message {
8
NSLog(@"onMessageOpened: %@", message.payload);
9
}
Copied!

Enabling Push Notifications

Go to Signing and Capabilities in your target. Press + Capability and add Push Notifications.
Last modified 7mo ago