Customizing iOS SDK

Customize Pushwoosh iOS SDK to meet your goals and preferences

Background modes

To ensure that Pushwoosh SDK always receives the push token it is highly recommended to enable the Remote notifications option from the Background modes section of the Capabilities tab in your Xcode project. You can also enable this support by including the UIBackgroundModes key with the remote-notification value in your app’s Info.plist file.

Notification alert in foreground

By default Pushwoosh iOS SDK displays the notification banner when the app is running in the foreground. You can control this behavior by setting the following boolean flag in your code (i.e. in your AppDelegate):

[PushNotificationManager pushManager].showPushnotificationAlert = 0; //set 0 to disable foreground notications, 1 to enable it

Controlling Log Level

To assist with debugging and integration, SDK will print all requests to the console by default. When you are ready for the production build, set "Pushwoosh_LOG_LEVEL" string key in your Info.plist file to one of the following values, depending on how much you want to see:

NONE - No logs from SDK ERROR - Only display errors in console WARNING - Also display warnings INFO - Add informational messages DEBUG - Add debug information VERBOSE - Everything SDK can print and more

Deep linking

In your Info.plist file add URL types array with URL Identifier and URL Scheme. In the example below the URL Scheme is com.pushwoosh and the URL Identifier is promotion.

In your App Delegate file (usually AppDelegate.m) add openURL delegate function as outlined in the example below. The example checks for the correct page, parses "id" value from the URL and opens PromoPageViewController in response.

Swift
Objective-C
Swift
func open(_ url: URL, options: [String : Any] = [:], completionHandler completion: ((Bool) -> Swift.Void)? = nil) {
let components = URLComponents(url: url, resolvingAgainstBaseURL: false)
let page = components?.host
var promotionId: String?
if page == "promotion" {
return
}
let items = components?.queryItems ?? []
for item in items {
if item.name == "id" {
promotionId = item.value
}
}
//show PromoPageViewController
}
Objective-C
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
NSString *page = components.host;
NSString *promotionId = nil;
//return if this is not a promotion deep link
if(![page isEqualToString:@"promotion"])
return NO;
for(NSURLQueryItem *item in components.queryItems)
{
if([item.name isEqualToString:@"id"])
promotionId = item.value;
}
PromoPageViewController *vc = [[PromoPageViewController alloc] init];
vc.promotionId = promotionId
[self presentViewController:vc animated:YES completion:nil];
}

In-Apps Tracking

In paymentQueue:updatedTransactions: delegate method call sendSKPaymentTransactions method of PushManager

Swift
Objective-C
Swift
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
PushNotificationManager.push().sendSKPaymentTransactions(transactions)
//the rest of the code, consume transactions, etc
}
Objective-C
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
[[PushNotificationManager pushManager] sendSKPaymentTransactions:transactions];
//the rest of the code, consume transactions, etc
}

Geozones push notifications

Gezones push notifications are encapsulated into a separate framework PushwooshGeozones.

1. To add PushwooshGeozones.framework to your project using a dependency manager, put the following lines in your podfile or cartfile:

Podfile
Carfile
Podfile

target 'MyApp' do pod 'Pushwoosh/Geozones' end

Carfile

github "Pushwoosh/pushwoosh-ios-sdk"

Also, you can simply drag and drop the framework into Link Binaries With Libraries in your project's Build Phases.

2. Add the following keys to your Info.plist:

  • NSLocationWhenInUseUsageDescription(required) for app to track Geozones only while running in the foreground.

  • NSLocationAlwaysAndWhenInUseUsageDescription - (required) for app to track Geozones in both conditions and to show a permission request dialog pop-up.

  • NSLocationAlwaysUsageDescription(optional) for app to track Geozones at all times; should be used if your app targets iOS 10 and earlier versions.

3. Import the framework:

Swift
Objective-C
Swift
import PushwooshGeozones
Objective-C
#import <PushwooshGeozones/PWGeozonesManager.h>

4. Start Geozones tracking when needed:

Swift
Objective-C
Swift
PWGeozonesManager.shared()?.startLocationTracking()
Objective-C
[[PWGeozonesManager sharedManager] startLocationTracking];

Creating a Rich Media queue

In case there are several Rich Media pages to display simultaneously (for example, trigger events for two or more In-Apps take place at one moment, or a Rich Media page is being displayed already at the moment a different trigger event occurs), you can set up a queue for Rich Media pages displaying. To create a queue, follow the steps described below.

  1. Create a class which implements PWRichMediaPresentingDelegate:

@interface ChainedRichMediaPresentingDelegate () <PWRichMediaPresentingDelegate>
@property (nonatomic) NSMutableArray *queue;
@property (nonatomic) BOOL inAppIsPresenting;
@end
@implementation ChainedRichMediaPresentingDelegate
- (instancetype)init {
self = [super init];
if (self) {
_queue = [NSMutableArray new];
}
return self;
}
- (BOOL)richMediaManager:(PWRichMediaManager *)richMediaManager shouldPresentRichMedia:(PWRichMedia *)richMedia {
[_queue addObject:richMedia];
return !_inAppIsPresenting;
}
- (void)richMediaManager:(PWRichMediaManager *)richMediaManager didPresentRichMedia:(PWRichMedia *)richMedia {
_inAppIsPresenting = YES;
}
- (void)richMediaManager:(PWRichMediaManager *)richMediaManager didCloseRichMedia:(PWRichMedia *)richMedia {
_inAppIsPresenting = NO;
[_queue removeObject:richMedia];
if (_queue.count) {
[[PWRichMediaManager sharedManager] presentRichMedia:_queue.firstObject];
}
}
- (void)richMediaManager:(PWRichMediaManager *)richMediaManager presentingDidFailForRichMedia:(PWRichMedia *)richMedia withError:(NSError *)error {
[self richMediaManager:richMediaManager didCloseRichMedia:richMedia];
}
@end

2. Set the delegate:

[PWRichMediaManager sharedManager].delegate = [ChainedRichMediaPresentingDelegate new];

Custom UNNotificationCenterDelegate

If you want to use your own UNNotificationCenterDelegate (for example, for local notifications), you should inform Pushwoosh SDK about it for proper behavior. You can do it with the notificationCenterDelegateProxy property of Pushwoosh instance:

Swift
Objective-C
Swift
Pushwoosh.sharedInstance()?.notificationCenterDelegateProxy.add(my_delegate)
Objective-C
[Pushwoosh.sharedInstance.notificationCenterDelegateProxy addNotificationCenterDelegate:my_delegate];

Then, implement UNNotificationCenterDelegate methods in your delegate:

Swift
Objective-C
Swift
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
if (!PWMessage.isPushwooshMessage(notification.request.content.userInfo)) {
// handle your notification
completionHandler(UNNotificationPresentationOptions.alert)
}
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
if (!PWMessage.isPushwooshMessage(response.notification.request.content.userInfo)) {
// handle your notification
completionHandler()
}
}
Objective-C
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
if (![PWMessage isPushwooshMessage:notification.request.content.userInfo]) {
//handle your message
completionHandler(UNNotificationPresentationOptionAlert);
}
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler {
if (![PWMessage isPushwooshMessage:response.notification.request.content.userInfo]) {
//handle your message
completionHandler();
}
}