SDK: Swift / Obj-C
Last updated
Last updated
The iOS (Swift / Obj-C) SDK is currently in closed beta. Contact your account manager for more information on becoming a beta partner.
Before you can integrate the SDK with your app the following requirements must be met:
An iOS 11+ device (iPhone, iPad, or iPod Touch) to develop and test on.
Note: The XCode Simulator does not support remote push notifications. A physical device must be used.
A Mac OS device with XCode 14+ (Swift 5.7, if using Swift) installed.
An iOS P12 Push Certificate or P8 Key. If you do not already have these follow our documentation to generate them.
SDK Key: Obtained from the Pushly Platform in the Domain Settings
page under the Overview
> Details
> Domain Information
section.
The PushSDK Framework is compatible with both Swift and Objective-C.
Select the root project and then your primary application target > General
Click +
> Add Other
> Add Package Dependency
under Frameworks, Libraries, and Embedded Content
Search using the Package URL: https://github.com/pushly/push-sdk-ios
Set the Dependency Rule to: Range of Versions
and 1.0.0
< 2.0.0
Click Add Package
Ensure the Pushly
option is checked and click Add Package
Finally, add the Pushly
library to the Primary Application Target
The Notification Service Extension is required to enable rich notifications that support images and custom actions.
Within your app's XCode project select File > New > Target
. Select Notification Service Extension
inside the iOS templates tab and click Next
.
Enter "NotificationServiceExtension" for the Product Name
and any other configuration details for your app extension and then click Finish
but do not click activate on the subsequent dialog.
Click Cancel
on the dialoging prompting you to activate the service extension so that you can set the deployment target once the modal is closed.
Make sure to set your deployment target to the same as your primary application target. Unless you have a specific reason not to, you should set the Deployment Target
to be iOS 11 which is the lowest supported version of iOS in the PushSDK Framework and in the most recent releases of XCode.
Next, add the Pushly
library to your Notification Service Extension:
Click +
under Frameworks and Libraries
and select the already imported Pushly
library.
Now, open the newly created Notification Service Extension and replace the code with the following:
You can ignore dependency errors, such as Module Pushly not found
, at this point as they will be resolved during the next build.
The Push Notifications capability should only be added to the primary application target.
Select the root project and then your primary application target > Signing & Capabilities
Click the + Capability
and add Push Notifications
.
Click the + Capability
and add Background Modes
.
After adding the Background Modes
capability ensure that Remote Notifications
are enabled.
Click the + Capability
and add App Groups
.
Click the +
symbol located inside the App Groups
section to add a new named container. To ensure that the PushSDK can properly capture information the container should be named group.{app-bundle-id}.push
.
Check the box next to the newly created App Group in the primary application target.
If Xcode complains about the new app group at this point you may need to refresh the list after it is done provisioning.
Select the root project and then the NotificationServiceExtension > Signing & Capabilities
Click the + Capability
and add App Groups
.
Finally, check the box next to the newly created App Group in the NotificationServiceExtension
.
First import the Pushly
library in your AppDelegate
Add the following code to the AppDelegate's didFinishLaunchingWithOptions
method of your application.
Replace the REPLACE_WITH_SDK_KEY
in the setConfiguration
method with the SDK Key from the platform settings page.
Run your app on a physical iOS device to make sure it builds correctly.
Note: The XCode Simulator does not support remote push notifications. A physical device must be used.
The code you added in the previous step will show the push permission dialog upon app open. This can be customized using SDK methods to control when the dialog shows.
After accepting the dialog, log into the platform and navigate to Notifications > Create Notification
and send your first notification, targeting the Native: iOS channel, to your device.
Once you have confirmed the SDK is working properly you may continue to add additional optional functionality like: