Download SDK Sample Project SDK API Docs
To integrate Pushwoosh into your application:
Add Pushwoosh.framework to your project.
In Info.plist add the Pushwoosh_APPID
key with your Pushwoosh Application ID string value.
Required code changes:
3.1. Add import definitions to your AppDelegate file.
import PushKitimport Pushwoosh
#import <Pushwoosh/Pushwoosh.h>
3.2. In the applicationDidFinishLaunching
function add:
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 controllerPushwoosh.sharedInstance().delegate = self// handling push on app startPushwoosh.sharedInstance().handlePushReceived(aNotification.userInfo)// register for push notifications!Pushwoosh.sharedInstance().registerForPushNotifications()
- (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).
// system push notification registration success callback, delegate to PWMessagingDelegatefunc application(_ application: NSApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {Pushwoosh.sharedInstance()?.handlePushRegistration(deviceToken)}// system push notification registration error callback, delegate to PWMessagingDelegatefunc application(_ application: NSApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {Pushwoosh.sharedInstance()?.handlePushRegistrationFailure(error)}
// 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)
//this event is fired when the push gets receivedfunc pushwoosh(_ pushwoosh: Pushwoosh!, onMessageReceived message: PWMessage!) {print("onMessageReceived: \(String(describing: message.payload))")}//this event is fired when user taps the notificationfunc pushwoosh(_ pushwoosh: Pushwoosh!, onMessageOpened message: PWMessage!) {print("onMessageOpened: \(String(describing: message.payload))")}
//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!