Customizing iOS SDK
Customize Pushwoosh iOS SDK to meet your goals and preferences
Requirements
Create a Pushwoosh account if you do not already have one.
A 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. For details, please read the iOS configuration guide.
Integration
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):
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.
In-app purchase tracking
By default, tracking of in-app purchases is disabled. If you want to track in-app purchases when configuring Customer Journeys, set the Pushwoosh_PURCHASE_TRACKING_ENABLED flag to true in the info.plist file. You can find a list of available flags in the table below.
If you want to track in-app purchases manually, you can use the code below.
In paymentQueue:updatedTransactions: delegate
method call sendSKPaymentTransactions method
of PushManager
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
:
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:
4. Start Geozones tracking when needed:
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.
Create a class that implements PWRichMediaPresentingDelegate:
2. Set the delegate:
Autoplay a video sent in a Rich Notification with force touch
To make a video sent as a Rich Notification attachment autoplay when the notification is expanded without any user interaction, follow the steps below:
Add the Notification Content Extension to your project:
In Xcode, select File > New > Target.
Choose Notification Content Extension.
Assign it a name and complete the setup.
If prompted with the "Activate scheme" message, choose Cancel.
Adjust the properties and methods in the Content Extension as follows:
Incorporate a UIView into MainInterface.storyboard:
Link the playerBackgroundView IBOutlet with the UIView you just added:
Update the info.plist file with the following entry:
In order to attach a video to your notification, input a videoโs URL to the Media Attachment field in the Control Panel:
When sending a notification via API /createMessage request, include the URL in the "ios_attachment" parameter and ensure the "mutable-content" flag is set to `1`.
To test the autoplay feature, you can use the following sample video: Hello World Sample Video.
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:
Then, implement UNNotificationCenterDelegate methods in your delegate:
Custom push sound
To play a custom sound when on a push notification receiving, first put the audio file into your project's root folder. For example, here's the Pushwoosh sample app with the sound files included: https://github.com/Pushwoosh/pushwoosh-ios-sdk/tree/master/Samples/iPhone
Then, specify the sound file's name in push parameters โ fill in the Sound field of the iOS-specific settings of your message or specify the file name as a value for the "ios_sound" param of the createMessage API request.
Audio file for custom iOS sound has to be in one of the following formats: .aif, .caf, .wav. Make sure to specify the format in the file's name; otherwise, it will be ignored by Pushwoosh iOS SDK.
Consider App Store limitations on bundle size when adding the sound file to your bundle.
Complete list of iOS SDK Info.plist properties
Property | Description | Possible values |
---|---|---|
Pushwoosh_APPID | Sets the Pushwoosh application ID for production build | XXXXX-XXXXX Type: String |
Pushwoosh_APPID_Dev | Sets the Pushwoosh application ID for development build | XXXXX-XXXXX Type: String |
Pushwoosh_SHOW_ALERT | Shows notification foreground alert | YES (default) / NO Type: Boolean |
Pushwoosh_ALERT_TYPE | Sets the notification alert style | BANNER (default) / ALERT / NONE Type: String |
Pushwoosh_BASEURL | Overrides the Pushwoosh server base url | https://cp.pushwoosh.com/json/1.3/ (default) Type: String |
Pushwoosh_AUTO_ACCEPT_DEEP_LINK_FOR_SILENT_PUSH | If YES, Deep Links received in silent pushes will be processed automatically | YES (default) / NO Type: Boolean |
Pushwoosh_ALLOW_SERVER_COMMUNICATION | Allows the SDK to send network requests to Pushwoosh servers | YES (default) / NO Type: Boolean |
Pushwoosh_ALLOW_COLLECTING_DEVICE_DATA | Allows the SDK to collect and to send device data (OS version status, locale and model) to the server | YES (default) / NO Type: Boolean |
Pushwoosh_ALLOW_COLLECTING_DEVICE_OS_VERSION | Allows the SDK to collect and to send device OS version to the server | YES (default) / NO Type: Boolean |
Pushwoosh_ALLOW_COLLECTING_DEVICE_LOCALE | Allows the SDK to collect and to send device locale to the server | YES (default) / NO Type: Boolean |
Pushwoosh_ALLOW_COLLECTING_DEVICE_MODEL | Allows the SDK to collect and to send device model to the server | YES (default) / NO Type: Boolean |
Pushwoosh_LOG_LEVEL | Pushwoosh SDK logging level. For details, refer to Controlling Log Level | NONE / ERROR / WARNING / INFO / DEBUG (default) / VERBOSE Type: String |
Pushwoosh_PURCHASE_TRACKING_ENABLED | Allows the SDK to track in-app purchases. Needed for Customer Journey Builder. | YES / NO (default) Type: Boolean |
iOS Provisional Push
Supported on iOS 12 and later.
How it works
Provisional push notifications appear silently in the userโs Notification Center but not on the lock screen. This type of pushes doesnโt need to be allowed by a user explicitly: you can start sending them as soon as a user installs and launches your app.
However, users still can subscribe to your prominent push notifications: when opening the Provisional Push, they have two options to choose their experience โ to keep pushes in Notification Center without alerts and sounds or allow you to send pushes prominently so that they appear on the lock screen.
Provisional Pushes are designed to let users make informed decisions about whether theyโd like to receive notifications from your app. As the APN native subscription request is shown to users only once and to subscribe later, they should go to their phoneโs system settings, and some users might not subscribe since they arenโt aware of what value they get with your pushes. Provisional Pushes give users this understanding: they can see what content you deliver in push notifications and decide whether they need to be notified about this content prominently.
Important!
Please note that Provisional Pushes, when implemented, replace the native APN prompt, which means users cannot subscribe to prominent notifications until they open their Notification Center and choose to receive Provisional Pushes as prominent ones.
How to implement
1. Integrate the Pushwoosh iOS SDK by following the guide.
2. Add the following string to your project's AppDelegate before calling the registerForPushNotifications()
method:
That's it! App users will receive messages directly to their Notification Center once they install the app.
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.
Last updated