Docs

  • Channels Channels
  • Beams Beams
  • Developers
  • Support
  • Blog
  • Sign up
    • Search powered by Algolia
    • Sign in
    • Sign up
    • Channels
    • Beams
    • Getting started
      • Android
        • 1. Configure FCM
        • 2. Integrate SDK
        • 3. Initialize Beams
        • 4. Publish Notifications
      • iOS
        • 1. Configure APNS
        • 2. Integrate SDK
        • 3. Publish Notifications
      • Web
        • 1. SDK integration
        • 2. Safari configuration
      • Flutter
        • 1. Configure FCM and APNS
        • 2. Integrate SDK
        • 4. Publish Notifications
    • Concepts
      • Subscribers
      • Device interests
      • Authenticated users
      • Insights
      • Webhooks
    • Guides
      • Handle incoming notifications
        • Android
        • iOS
        • Web
        • Flutter
      • Publishing to multiple devices
      • Publish to specific user
        • Android
        • iOS
        • Web
        • Flutter
      • Web push guides
        • Using an existing service worker
        • Web notification permissions in Firefox
        • Handling Safari certificate expiration
    • Reference
      • Client SDKs
        • Android
        • iOS
        • Web
      • All Libraries
      • Server SDKs
        • Go
        • PHP
        • Node.js
        • Python
        • Java/Kotlin
        • Ruby
        • Swift
      • API
        • Publish API
        • Customer API
        • Device API
        • Reporting API
        • Webhooks
      • Platform Publish Formats
    • Pusher lab

    Integrate iOS SDK

    Our Beams service lets you subscribe iOS devices to interests. When your servers publish push notifications to interests, the iOS devices subscribed to the relevant interests will receive them. Your iOS application can subscribe to interests using our Swift SDK. This page guides you through setting up your iOS application to register, subscribe to interests, and receive push notifications pushed to those interests.

    ∞ Minimum Requirements

    Xcode - The easiest way to get Xcode is from the App Store , but you can also download it from developer.apple.com if you have an AppleID registered with an Apple Developer account.

    ∞ Install from CocoaPods

    CocoaPods is a dependency manager for Cocoa projects. You can install it with the following commands:

    gem install cocoapods

    Create an empty Podfile:

    pod init

    To integrate Beams into your Xcode project using CocoaPods, specify it in your Podfile:

    pod 'PushNotifications'

    Run the following command:

    pod install

    When installation is complete open the .xcworkspace that was created.

    ∞ Install from Carthage

    Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

    You can install Carthage with Homebrew using the following command:

    brew update && brew install carthage

    To integrate Beams into your Xcode project using Carthage, specify it in your Cartfile:

    github "pusher/push-notifications-swift"

    Run carthage bootstrap to build the framework and drag the built PushNotifications.framework into your Xcode project.

    ∞ Enable Capabilities

    In the project navigator, select your project, and click on the Signing & Capabilities tab. Enable Push Notifications by clicking on the “+ Capability” button.

    Enable Remote notifications in the Background Modes section.

    Screenshot from xCode showing Remote Notifications checked

    ∞ Register with APNs

    For your iOS app to receive push notifications, it must first register the device with APNs. You should do this when the application finishes launching, i.e. in its application:didFinishLaunchingWithOptions: handler:

    import UIKit
    import PushNotifications

    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    let beamsClient = PushNotifications.shared

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.launchOptionsKey: Any]?) -> Bool {
    self.beamsClient.start(instanceId: "YOUR_INSTANCE_ID")
    self.beamsClient.registerForRemoteNotifications()

    return true
    }
    }

    ∞ Register with Pusher

    APNs will provide a device token identifying your app instance. This device token is passed to your application with the application:didRegisterForRemoteNotificationsWithDeviceToken: method. Pusher requires the deviceToken in order to send push notifications to the app instance. Your app should register with Push Notifications, passing along its device token. Add a handler for it:

    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    self.beamsClient.registerDeviceToken(deviceToken)
    }

    ∞ Add a device interest

    Subscribe the app to the interest hello:

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    self.beamsClient.start(instanceId: "YOUR_INSTANCE_ID")
    self.beamsClient.registerForRemoteNotifications()
    try? self.beamsClient.addDeviceInterest(interest: "hello")

    return true
    }

    When your server publishes a push notification to the interest hello, it will get passed to your app. This happens as a call to application:didReceiveRemoteNotification:fetchCompletionHandler: in your AppDelegate:

    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    print(userInfo)
    }

    ∞ Notification delivery for iOS 13 and above

    Please read these notes for a guide on how to ensure timely notification delivery to your app on iOS 13 and above.

    ∞ Where Next?

    Now that you have integrated the SDK into your iOS project why not send a notification?

    Contents

    • Minimum Requirements
    • Install from CocoaPods
    • Install from Carthage
    • Enable Capabilities
    • Register with APNs
    • Register with Pusher
    • Add a device interest
      • Notification delivery for iOS 13 and above
    • Where Next?

    Spotted something that isn’t quite right? Create an issue on GitHub.

    Copyright © 2024 Pusher Ltd. All rights reserved.

    • Support,
    • Status
    • Follow Pusher on Twitter Twitter
    • Subscribe to Pusher’s channel on YouTube
    • Follow Pusher on LinkedIn
    • Follow Pusher on Github GitHub
    • Follow Pusher on Twitch Twitch
    • Follow Pusher on Discord Discord