LogoLogo
No-code docsResources
  • 🖥️Welcome to the Bird API Docs
  • API Access
    • Access Policies
    • Access Roles
    • API Authorization
    • Common API usage
  • Conversations API
    • API reference
      • Channel configuration
        • Get conversations configuration
        • Update conversations configuration
      • Conversations messaging
        • Create conversation message
        • List conversation messages
        • Get conversation message
        • Update conversation message
        • Delete conversation message
        • Create pre-signed upload
      • Conversations management
        • Create conversation
        • List conversations
        • Get conversation
        • Update conversation
        • Delete conversation
      • Conversation Participants
        • Add participant to conversation
        • List participants
        • Get participant by ID
        • Get participant by identifier key and value
        • Update participant by ID
        • Update participant by identifier key and value
        • Delete participant
        • List participant conversations by ID
        • List participant conversations by identifier key and value
      • Workspace settings
        • Get antispam setting
        • Update antispam setting
        • Create allow/block rule
        • Get allow/block rule
        • List allow/block rules
        • Update allow/block rule
        • Delete allow/block rule
        • Add allow/block rules in bulk
        • Get allow/block bulk upload status
      • Events
  • Collaborations API
    • API reference
      • Agent Management
      • Team Management
      • Feeds
      • Feed item activity
      • Tags
      • Automation Rules
      • Business Hours
      • Capacity Rules
      • Routing Queues
      • Skills
      • SLA Policies
      • Macros
      • Sender Profiles
      • Ticket fields
  • Channels API
    • Supported channels
      • Programmable WhatsApp
        • Sending WhatsApp messages
        • Customer service window
        • Receiving messages
        • Message interactions
        • WhatsApp ISV integration
          • Setting up your customer workspaces
            • API Access
            • Associating your Facebook solution ID and business ID with your Bird CRM Organization
            • Creating a workspace for your customer
            • Buying a number through Bird
            • Subscribing to channel created webhooks
          • WhatsApp channel onboarding
            • Setting up the WhatsApp Embedded flow
            • Install WhatsApp phone number in Bird CRM
            • Subscribe to channel webhooks
      • Programmable SMS
        • Installing an SMS channel
          • US 10DLC API Installation
          • Toll-Free Numbers Verification API
        • Sending SMS messages
        • Receiving messages
        • Twilio Exit API
          • Using Twilio PHP SDK
          • Using Twilio Go SDK
          • Using Twilio Ruby SDK
        • Sinch Exit API
      • Programmable RCS
        • Sending messages
        • Receiving messages
        • Message interactions
      • Programmable Email
        • Sending Emails
        • Receiving messages
        • Message status
        • Message interactions
      • Programmable Line
        • Sending messages
        • Receiving messages
        • Message interactions
      • Programmable Telegram
        • Sending messages
        • Receiving messages
        • Message interactions
    • Message types
      • Text
      • Images
      • Files
      • List
      • Carousel
      • Template
    • Message status and interactions
      • Message Failure Codes
      • Message Failure Sources
        • SMS Platform Extended Error Codes
    • Send batch messages
    • API reference
      • Channel Groups
      • Messaging
      • Channels management
      • Channel connectors
      • Navigators
      • Compliance Keywords Messages
      • Conversions Sharing
      • Events
    • Rate Limit
  • Voice API
    • Installing a Voice channel
    • Voice Calls API
      • Initiate an outbound call
      • List calls from a channel
      • Get a call
      • Update a call
      • Answer a call
      • Ring a call
      • Hangup a call
      • Play a message in a call
      • Say Text-To-Speech (TTS)
      • Gather DTMF from a call
      • Forward a call
      • Record a Call
      • Record a call session
      • Update a call recording
      • List call recordings of a call
      • Get a call recording
      • Get a call insights
      • Get calls log
    • Recordings API
      • List Recordings
      • Get a Recording
      • Delete a Recording
      • List recording storage metrics
    • Transcriptions API
      • Initiate a Transcription
      • List Transcriptions
      • Get a Transcription
      • Delete a Transcription
    • Voice webhooks
    • Flash Calling API
  • Verify API
    • Verify API: Quick Start
  • Contacts API
    • Tracking Contact Events
      • API Reference
        • Get configuration
        • Track events
    • API reference
      • Manage workspace contacts
        • Create a contact
        • Get a contact
        • List contacts
        • Search contact by identifier
        • Update a contact
        • Create or update a contact by identifier
        • Delete a contact
      • Manage contact identifiers
        • Create contact identifier
        • List contact identifiers
        • Delete contact identifier
      • Manage contact attribute definition
        • Create attribute definition
        • Get attribute definition
        • List attribute definitions
      • Manage contact lists
        • Create a list
        • Get a list
        • List lists
        • Update a list
        • Delete a list
        • Add contacts to a list
        • Get contact list memberships
        • List contacts in a list
        • Remove contacts from a list
      • Lookup
        • Network/Country information for a phone number
  • Numbers API
    • API reference
      • Search Available Numbers
      • Buy a Number
      • List your Numbers
      • Get Long Code Number Details
      • Manage Endpoint Subscriptions
        • Cancel Number Subscription
      • Manage Endpoint Compliance Requirements
        • List Workspace compliace Requirements
        • Get Workspace Compliace Requirements
        • Update Workspace Compliace Requirements
      • 10DLC Compliance
        • Brands - Organization
          • Create a brand
          • List all brands
          • Get a brand
          • Update a brand
          • Delete a brand
          • Create a brand vetting
        • Brands - workspace
          • Create a brand
          • List all brands
          • Get a brand
          • Update a brand
          • Delete a brand
          • Create a brand vetting
          • List brand vettings
        • Campaigns
          • Optional: acting as Reseller
          • Create a campaign
          • List all campaigns
          • Get a campaign
          • Update a campaign
          • Delete a campaign
        • TCR Enums
        • Events
      • Toll-Free Numbers Verification API
      • Long Code Numbers
      • Short Code Numbers
      • Alphanumeric Senders
      • Events
  • Know-Your-Customer (KYC) API
    • List KYC forms
    • Get KYC form
    • Create KYC form entry
    • Update KYC form entry
    • List KYC form entries
    • Get a KYC form entry details
  • Reporting API
    • API reference
      • Channel Metrics
      • Flow Run Metrics
      • Wallet Metrics
      • Campaign Metrics
      • Message Metrics
  • Accounts API
    • API reference
      • Current user
        • Change password
        • Presigned upload
        • Memberships
        • Sessions
        • Configurations
          • Groups
            • Keys
      • IAM policies
      • Organizations
        • Upload media
        • Profile
        • Workspaces
        • Users
        • Access keys
        • Organization roles
        • Organization policies
        • Teams
          • Members
        • Approvals
          • Runs
            • Reviews
        • Configurations
          • Groups
            • Keys
      • Region groups
  • Touchpoints API
    • Supported Projects
      • Whatsapp Approved Message Templates
        • Creating WhatsApp Message templates
          • Text template blocks
          • Blocks Documentation
    • API reference
      • Projects
      • Message Templates
  • Notifications API
    • API Reference
      • Webhook subscriptions
        • Create a webhook subscription
        • List available webhook events
        • Get a webhook subscription
        • List webhook subscriptions
        • Update a webhook subscription
        • Delete a webhook subscription
        • Verifying a webhook subscription
        • Webhook subscription logs
  • Knowledge Base (KB) API
    • API reference
      • Documents
      • Folders
        • Import
      • Search
      • Presigned upload
  • Email API
    • Transmissions
  • Connectivity platform migration guide
    • Channels API and Conversations API
    • Migrating conversations API actions
    • Migrating WhatsApp channels
  • Client SDKs
    • Applications
    • Contact Profiles
      • Signed Identity
    • Push notifications
      • Quick Start
      • Subscribe contacts to push notification campaigns
      • Notification Display Priority
    • Event Tracking
      • Quick Start
      • Track Events
        • App
        • Audiences
        • Conference
        • Ecommerce
        • Hospitality
        • Lists
        • Messaging
        • Payments
        • Subscription
        • Suppressions
        • Survey
        • Web
    • App Inbox
      • Quick Start
      • Usage
      • Subscribe contacts to app inbox campaigns
    • SDK Integration
      • Android SDK
        • Notification Interactions
      • Swift SDK
        • Notification Interactions
      • Web SDK
        • Quick Start
        • Usage
        • API Reference
          • IdentityManager
          • BirdSdkApi
          • BirdTracker
            • Ecommerce
            • Conference
            • Messaging
            • Suppressions
            • Subscription
            • Survey
            • Web
            • Audiences
        • Web Push Notifications
          • Notification Interactions
  • Quickstarts
    • Conversations
    • Send an SMS message
    • Send an Email message
    • Send a WhatsApp message
Powered by GitBook
On this page
  • 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 and Keychain sharing
  • Examples

Was this helpful?

  1. Client SDKs
  2. SDK Integration

Swift SDK

Last updated 9 months ago

Was this helpful?

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

  1. In your application in Xcode. Go to File > Add Packages Dependencies to add a new dependency.

  2. Specify the URL of the Bird Swift SDK .

  3. 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.

  1. Inside Info.list file, add an entry for Bird with type Dictionary.

  2. Then add the following fields with type String inside the Bird dictionary

    • ApplicationKey: You can get the value of this application key from "Bird Dashboard / Preferences / Applications".

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

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 tab

  • Click on + Capability and add the following Capabilities:

    • Push Notifications

    • Background Modes

  • From Background Modes section, select Remote 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 member

  • bird.notifications.registerDevice is called inside the method with argument didRegisterForRemoteNotificationsWithDeviceToken

  • bird.notifications.applicationDidReceiveRemoteNotification is called inside the method with argument didReceiveRemoteNotification

  • bird.notifications.willPresentNotification and bird.notifications.didReceiveResponse(response) are called from the corresponding methods of UNUserNotificationCenterDelegate

class AppDelegate: NSObject, UIApplicationDelegate {
    static var bird: Bird!
    static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "AppDelegate")
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        do {
            AppDelegate.bird = try Bird()
        } catch {
            Self.logger.log("failed to create bird")
        }
        
        UNUserNotificationCenter.current().delegate = self
        return true
    }
    
    func application(
        _ application: UIApplication,
        didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
    ) {
        Self.bird.notifications.registerDevice(deviceToken: deviceToken) 
    }
    
    func application(
        _ application: UIApplication,
        didReceiveRemoteNotification userInfo: [AnyHashable : Any],
        fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void
    ) {
        Self.bird.notifications.handleBackgroundNotification(
            userInfo: userInfo, 
            completionHandler: completionHandler
        )
    }
    
    // Call this method to request notifications permissions
    static func requestNotificationsPermission() {
        UNUserNotificationCenter.current().requestAuthorization(
            options:[.badge, .alert, .sound]
        ) { granted, error in
            guard granted else {
                self.logger.log("Notification permission is not gratned")
                return
            }
            DispatchQueue.main.async {
                UIApplication.shared.registerForRemoteNotifications()
            }
        }
    }
}

extension AppDelegate: UNUserNotificationCenterDelegate {
    func userNotificationCenter(
        _ center: UNUserNotificationCenter,
        willPresent notification: UNNotification,
        withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
    ) {
        let options = Self.bird.notifications.willPresentNotification(notification)
        completionHandler(options)
    }

    func userNotificationCenter(
        _ center: UNUserNotificationCenter,
        didReceive response: UNNotificationResponse,
        withCompletionHandler completionHandler: @escaping () -> Void
    ) {
        let result = Self.bird?.notifications.handleNotificationResponse(
            response: response,
            automaticallyOpenLinks: true
        )
        completionHandler()
    }
}

Then you need to use this class as your application delegate. In case you use Swift UI, here is an example:

import SwiftUI

@main 
struct DemoApp: App {
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

Step 5: Create Notification Service Extension

Add a Notification Service Extension to your project.

  1. Select File > New > Target in Xcode.

  2. Select the Notification Service Extension target from the iOS > Application section.

  3. Click Next.

  4. Specify a name and other configuration details for your app extension.

  5. Click Finish.

Then change the code in NotificationService.swift to only extend from BirdNotificationService as follows:

import BirdKit

class NotificationService: BirdNotificationService {
}

Step 6: Create Notification Content Extension

Add a Notification Content App Extension to Your Project

  1. Select File > New > Target in Xcode.

  2. Select Notification Content Extension from iOS Application Extension.

  3. Click Next.

  4. Provide a name for your app extension.

  5. Click Finish.

Then go ahead and do the following steps:

  1. Remove the storyboard file from the extension

  2. Remove the NSExtensionMainStoryboard entry from the extension's Info.plist.

  3. Add a new entry of NSExtensionPrincipalClass to the Info.plist under NSExtension. The value should be $(PRODUCT_MODULE_NAME).NotificationViewController

  4. Change the value for entry UNNotificationExtensionCategory to be BIRD

  5. Change NotificationViewController.swift to only extend BirdNotificationViewController as follows:

import BirdKit

class NotificationViewController: BirdNotificationViewController {
}

Step 7: Create App Group and Keychain sharing

  1. Select your project in XCode

  2. Select the target application of your project under TARGETS

  3. Go to Signing and Capabilities tab

  4. Click on + Capability and add the following Capabilities:

    • App Groups

    • Background Modes

    • Keychain sharing

  5. Inside App Groups section:

    • add a new App Group if needed

    • Select an App Group for this target

  6. 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)

  7. Do the same process of adding App Groups and select the same App Group for:

    • Notification Service Extension target

    • Notification Content Extension target

  • The iOS application target

  • Notification Service Extension target

  • Notification Content Extension target

Examples

AppGroup: This is the name of the app group you will create in .

AccessGroup: This is a name of the access group for keychain sharing you will create in . Usually it has the following format: {TEAM_ID}.{KEYCHAIN_GROUP}.

Notification Service Extension target. See .

Notification Content Extension target. See

Remember to add Bird configuration to Info.plist of Notification Service Extension target as explained in .

Remember to add Bird configuration to Info.plist of Notification Content Extension target as explained in .

The go ahead and add the AppGroup and AccessGroup to the Info.plist as explained in for each of the following:

You can find examples and report issue on the public repository .

https://github.com/messagebird/swift-sdk
messagebird/swift-sdk
Step 7: Create App Group & Keychain Group
Step 7: Create App Group & Keychain Group
Step 5: Create Notification Service Extension
Step 6: Create Notification Content Extension
Step 2: Set Application Key, App Group & Keychain group
Step 2: Set Application Key & App Group
Step 2: Set Application Key, App Group & Keychain Group