Setting up Pushwoosh iOS SDK

This guide describes the process of implementing Pushwoosh SDK into your Native iOS app

Download SDK Download Sample SDK API Docs

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
Podfile
target 'MyApp' do
pod 'Pushwoosh'
end
Cartfile
github "Pushwoosh/pushwoosh-ios-sdk"

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
Swift
import Pushwoosh
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, PWMessagingDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
//initialization code
//set custom delegate for push handling, in our case AppDelegate
Pushwoosh.sharedInstance()?.delegate = self;
//register for push notifications!
Pushwoosh.sharedInstance()?.registerForPushNotifications()
return true
}
//handle token received from APNS
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Pushwoosh.sharedInstance()?.handlePushRegistration(deviceToken)
}
//handle token receiving error
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
Pushwoosh.sharedInstance()?.handlePushRegistrationFailure(error);
}
//this is for iOS < 10 and for silent push notifications
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
Pushwoosh.sharedInstance()?.handlePushReceived(userInfo)
completionHandler(.noData)
}
//this event is fired when the push gets received
func pushwoosh(_ pushwoosh: Pushwoosh!, onMessageReceived message: PWMessage!) {
print("onMessageReceived: ", message.payload.description)
}
//this event is fired when user taps the notification
func pushwoosh(_ pushwoosh: Pushwoosh!, onMessageOpened message: PWMessage!) {
print("onMessageOpened: ", message.payload.description)
}
}
Objective-C
#import <Pushwoosh/Pushwoosh.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//-----------PUSHWOOSH PART-----------
// set custom delegate for push handling, in our case AppDelegate
[Pushwoosh sharedInstance].delegate = self;
//register for push notifications!
[[Pushwoosh sharedInstance] registerForPushNotifications];
return YES;
}
//handle token received from APNS
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[[Pushwoosh sharedInstance] handlePushRegistration:deviceToken];
}
//handle token receiving error
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
[[Pushwoosh sharedInstance] handlePushRegistrationFailure:error];
}
//this is for iOS < 10 and for silent push notifications
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[[Pushwoosh sharedInstance] handlePushReceived:userInfo];
completionHandler(UIBackgroundFetchResultNoData);
}
//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);
}
@end

Enabling Push Notifications

Go to Capabilities tab and toggle Push Notifications on. Also, tick the Remote notifications checkbox in Background Modes.

That's it!