Swift SDK
Bird Swift SDK is a single integration point to bring the power of BirdCRM in building connected user experience to your application.
Using Bird Swift SDK, you get access to:
Collect Contacts
Send Push Notifications
Integrating Bird Swift SDK into your application consists of the following steps:
Step 1: Add Bird Swift SDK dependency
Step 2: Set Application Key, App Group & Keychain Group
Step 3: Add Capabilities
Step 4: Create AppDelegate
Step 5: Create Notification Service Extension
Step 6: Create Notification Content Extension
Step 7: Create App Group & Keychain Group
Step 1: Add Bird Swift SDK dependency
You can add Bird Swift SDK as a dependency to your project using Swift Package Manager
In your application in Xcode. Go to File > Add Packages Dependencies to add a new dependency.
Specify the URL of the Bird Swift SDK https://github.com/messagebird/swift-sdk.
Select the
swift-sdk
package and click "Add Package"
Step 2: Set Application Key, App Group & Keychain group
All configuration for Bird Swift SDK can be set up in Info.plist
file in your application.
Inside
Info.list
file, add an entry forBird
with typeDictionary
.Then add the following fields with type
String
inside theBird
dictionaryApplicationKey: You can get the value of this application key from "Bird Dashboard / Preferences / Applications".
AppGroup: This is the name of the app group you will create in Step 7: Create App Group & Keychain Group.
AccessGroup: This is a name of the access group for keychain sharing you will create in Step 7: Create App Group & Keychain Group. Usually it has the following format:
{TEAM_ID}.{KEYCHAIN_GROUP}
.
Info.plist
should look like this:
These values need to be added to the Info.plist
file for each of the following:
The iOS application target
Notification Service Extension target. See Step 5: Create Notification Service Extension.
Notification Content Extension target. See Step 6: Create Notification Content Extension
Step 3: Add Capabilities
Open your application project in XCode.
Select your project in XCode
Select the target of your project under
TARGETS
Go to
Signing and Capabilities
tabClick on
+ Capability
and add the following Capabilities:Push Notifications
Background Modes
From
Background Modes
section, selectRemote notifications
Step 4: Create AppDelegate
You may already have an AppDelegate. If not, you need to create one like in the example below.
Notice that:
instance of
Bird
is created once and saved in a static memberbird.notifications.registerDevice
is called inside the method with argumentdidRegisterForRemoteNotificationsWithDeviceToken
bird.notifications.applicationDidReceiveRemoteNotification
is called inside the method with argumentdidReceiveRemoteNotification
bird.notifications.willPresentNotification
andbird.notifications.didReceiveResponse(response)
are called from the corresponding methods ofUNUserNotificationCenterDelegate
Then you need to use this class as your application delegate. In case you use Swift UI, here is an example:
Step 5: Create Notification Service Extension
Add a Notification Service Extension to your project.
Select File > New > Target in Xcode.
Select the Notification Service Extension target from the iOS > Application section.
Click Next.
Specify a name and other configuration details for your app extension.
Click Finish.
Then change the code in NotificationService.swift to only extend from BirdNotificationService
as follows:
Remember to add Bird
configuration to Info.plist
of Notification Service Extension target as explained in Step 2: Set Application Key, App Group & Keychain group.
Step 6: Create Notification Content Extension
Add a Notification Content App Extension to Your Project
Select File > New > Target in Xcode.
Select Notification Content Extension from iOS Application Extension.
Click Next.
Provide a name for your app extension.
Click Finish.
Then go ahead and do the following steps:
Remove the storyboard file from the extension
Remove the
NSExtensionMainStoryboard
entry from the extension's Info.plist.Add a new entry of
NSExtensionPrincipalClass
to the Info.plist underNSExtension
. The value should be$(PRODUCT_MODULE_NAME).NotificationViewController
Change the value for entry
UNNotificationExtensionCategory
to beBIRD
Change
NotificationViewController.swift
to only extendBirdNotificationViewController
as follows:
Remember to add Bird
configuration to Info.plist
of Notification Content Extension target as explained in Step 2: Set Application Key & App Group.
Step 7: Create App Group and Keychain sharing
Select your project in XCode
Select the target application of your project under
TARGETS
Go to
Signing and Capabilities
tabClick on
+ Capability
and add the following Capabilities:App Groups
Background Modes
Keychain sharing
Inside
App Groups
section:add a new App Group if needed
Select an App Group for this target
Inside
Keychain Sharing
section:Add a new Keychain Group (usually it has the same equals to bundle id of the main target of the app)
Do the same process of adding App Groups and select the same App Group for:
Notification Service Extension target
Notification Content Extension target
The go ahead and add the AppGroup
and AccessGroup
to the Info.plist
as explained in Step 2: Set Application Key, App Group & Keychain Group for each of the following:
The iOS application target
Notification Service Extension target
Notification Content Extension target
Examples
You can find examples and report issue on the public repository messagebird/swift-sdk.
Last updated