Links

iOS SDK CocoaPods Setup

iOS Setup With CocoaPods
Pushwoosh SDK iOS integration (CocoaPods)

Requirements

  • Create Pushwoosh account if you do not already have one.
  • Real device with iOS 9 and later. The Xcode simulator doesn't support push notifications so you must test on a real device.
  • A Mac with a new version of Xcode.
  • An iOS Push Certificate. Details see: iOS configuration

Integration

To integrate the iOS SDK, use the automatical integration script:
Or setup by the following commands:
  1. 1.
    Run 'pod init' command from the terminal in your project directory.
  2. 2.
    Open the newly created Podfile file.
  3. 3.
    Add Pushwoosh dependency to your Podfile
pod 'Pushwoosh'
Here's what your Podfile should look like:
Podfile
If you want to use Pushwoosh.xcframework, use pod 'PushwooshXCFramework' in your Podfile.

Catalyst integration

Catalyst uses .xcframework, so you should use PushwooshXCFramework pod instead of Pushwoosh:
pod 'PushwooshXCFramework'
4. Run the following command in your terminal in your project directory:
pod install
5. Open the newly created <your_project_name>.xcworkspace file.
6. Well done! You've just integrated Pushwoosh SDK to your project.
Cocoapods Setup

Add Required Capabilities

  1. 1.
    Select the root project (1), your main app target (2), then go to the "Signing and Capabilities" tab.
  2. 2.
    Press "+ Capability" button (3) and select the "Push Notifications" capability.
  3. 3.
    Then, add the "Background Modes" capability and check the "Remote notifications" check box (4).
Required Capabilities
4. Well done! Xcode capabilities configuration completed.
Add Required Capabilities
XCODE 13 Time Sensitive notifications
If you want to send Time Sensitive notifications, add the Time Sensitive Notifications capability (read more about time sensitive push notifications here).
Time Sensitive Notifications

Add iOS Message Delivery Tracking

There is an API method in Pushwoosh that tracks the delivery of push notifications. iOS apps do not support this method out of the box as push notifications in iOS are handled by the OS, not by Pushwoosh SDK. However, you can implement delivery tracking by adding the Pushwoosh Notification Service Extension for push delivery tracking to your project. Here you'll find the steps to implement Message Delivery Tracking for iOS apps.
Available on iOS 10.0 and later
1. Add Notification Service Extension
1.1. In Xcode, Select File > New > Target...
1.2. Select Notification Service Extension and press Next.
1.3 Enter the product name and press Finish.
Do not select Activate on the dialog that is shown after pressing Finish.
Press Cancel on the Activate scheme prompt.
By canceling, you are keeping Xcode debugging your app, instead of the extension you just created. If you activated it by accident, you can switch back to debug your app within Xcode.
2. Add code for tracking message delivery events
2.1 Add the following code to your NotificationService.m file:
#import "PWNotificationExtensionManager.h"
@interface NotificationService : UNNotificationServiceExtension
@end
@implementation NotificationService
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
[[PWNotificationExtensionManager sharedManager] handleNotificationRequest:request contentHandler:contentHandler];
}
- (void)serviceExtensionTimeWillExpire {
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
}
@end
2.2 Add Pushwoosh_APPID to your Notification Service Extension info.plist.
<key>Pushwoosh_APPID</key>
<string>XXXXX-XXXXX</string>

Add the Pushwoosh Initialization code

  1. 1.
    Add the following code to your AppDelegate class:
Swift
Objective-C
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 a user taps the notification
func 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 *)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
2. Platform configuration
Before adding Pushwoosh_APPID string type key to your info.plist, configure your platforn as show following:
3. In your Info.plist, add a string type key Pushwoosh_APPID with your Pushwoosh Application Code as a value.
<key>Pushwoosh_APPID</key>
<string>XXXXX-XXXXX</string>
Replace XXXXX-XXXXX with your Pushwoosh APP ID
4. Well Done! Now you can send your first push notification!

Share your feedback with us

Your feedback helps us create a better experience, so we would love to hear from you if you have any issues during the SDK integration process. If you face any difficulties, please do not hesitate to share your thoughts with us via this form.

Next steps