Download SDK Download Sample SDK API Docs
Add Pushwoosh.framework
to your project via a dependency manager by putting the following lines in your podfile
or cartfile
:
target 'MyApp' dopod '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.
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:
In your Info.plist, add a string type key Pushwoosh_APPID
with your Pushwoosh Application Code as value.
Add the following code to your AppDelegate:
import Pushwoosh@UIApplicationMainclass 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 AppDelegatePushwoosh.sharedInstance()?.delegate = self;//register for push notifications!Pushwoosh.sharedInstance()?.registerForPushNotifications()return true}//handle token received from APNSfunc application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {Pushwoosh.sharedInstance()?.handlePushRegistration(deviceToken)}//handle token receiving errorfunc application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {Pushwoosh.sharedInstance()?.handlePushRegistrationFailure(error);}//this is for iOS < 10 and for silent push notificationsfunc 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 receivedfunc pushwoosh(_ pushwoosh: Pushwoosh!, onMessageReceived message: PWMessage!) {print("onMessageReceived: ", message.payload.description)}//this event is fired when user taps the notificationfunc pushwoosh(_ pushwoosh: Pushwoosh!, onMessageOpened message: PWMessage!) {print("onMessageOpened: ", message.payload.description)}}
#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 *)applicationdidRegisterForRemoteNotificationsWithDeviceToken:(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 *)applicationdidReceiveRemoteNotification:(NSDictionary *)userInfofetchCompletionHandler:(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
Go to Capabilities tab and toggle Push Notifications on. Also, tick the Remote notifications checkbox in Background Modes.
That's it!