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
target 'MyApp' do
pod 'Pushwoosh'
end
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
import Pushwoosh
import UserNotifications
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, PushNotificationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
//initialization code
//set custom delegate for push handling, in our case AppDelegate
PushNotificationManager.push().delegate = self
//set default Pushwoosh delegate for iOS10 foreground push handling
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = PushNotificationManager.push().notificationCenterDelegate
}
// track application open statistics
PushNotificationManager.push().sendAppOpen()
// register for push notifications!
PushNotificationManager.push().registerForPushNotifications()
return true
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
PushNotificationManager.push().handlePushRegistration(deviceToken as Data)
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
PushNotificationManager.push().handlePushRegistrationFailure(error)
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
if #available(iOS 10.0, *) {
completionHandler(UIBackgroundFetchResult.noData)
} else {
PushNotificationManager.push().handlePushReceived(userInfo)
completionHandler(UIBackgroundFetchResult.noData)
}
}
//this event is fired when the push gets received
func onPushReceived(_ pushManager: PushNotificationManager!, withNotification pushNotification: [AnyHashable : Any]!, onStart: Bool) {
print("Push notification received: \(String(describing: pushNotification))")
// shows a push is received. Implement passive reaction to a push here, such as UI update or data download.
}
//this event is fired when user taps the notification
func onPushAccepted(_ pushManager: PushNotificationManager!, withNotification pushNotification: [AnyHashable : Any]!, onStart: Bool) {
print("Push notification accepted: \(String(describing: pushNotification))")
// shows a user tapped the notification. Implement user interaction, such as showing push details
}
}
#import <Pushwoosh/PushNotificationManager.h>
#import <UserNotifications/UserNotifications.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//lots of initialization code
// set custom delegate for push handling, in our case AppDelegate
PushNotificationManager * pushManager = [PushNotificationManager pushManager];
pushManager.delegate = self;
// set default Pushwoosh delegate for iOS10 foreground push handling
if (@available(iOS 10.0, *)) {
[UNUserNotificationCenter currentNotificationCenter].delegate = [PushNotificationManager pushManager].notificationCenterDelegate;
}
// track application open statistics
[[PushNotificationManager pushManager] sendAppOpen];
// register for push notifications!
[[PushNotificationManager pushManager] registerForPushNotifications];
return YES;
}
// system push notification registration success callback, delegate to pushManager
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[[PushNotificationManager pushManager] handlePushRegistration:deviceToken];
}
// system push notification registration error callback, delegate to pushManager
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
[[PushNotificationManager pushManager] handlePushRegistrationFailure:error];
}
// system push notifications callback, delegate to pushManager
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {
if (@available(iOS 10.0, *)) {
completionHandler(UIBackgroundFetchResultNoData);
} else {
[[PushNotificationManager pushManager] handlePushReceived:userInfo];
completionHandler(UIBackgroundFetchResultNoData);
}
}
// this event is fired when the push gets received
- (void)onPushReceived:(PushNotificationManager *)pushManager withNotification:(NSDictionary *)pushNotification onStart:(BOOL)onStart {
NSLog(@"Push notification received");
// shows a push is received. Implement passive reaction to a push, such as UI update or data download.
}
// this event is fired when user taps the notification
- (void)onPushAccepted:(PushNotificationManager *)pushManager withNotification:(NSDictionary *)pushNotification onStart:(BOOL)onStart {
NSLog(@"Push notification accepted");
// shows a user tapped the notification. Implement user interaction, such as showing push details
}
@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!