> ## Documentation Index
> Fetch the complete documentation index at: https://social-b97141fb-auto-generate-llmstxt.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# iOS Push Notifications

> Register APNs device tokens with the current social.plus iOS SDK.

iOS push setup has two parts: configure APNs for your app, then register the APNs device token with the social.plus iOS SDK after the user is signed in.

<Warning>
  Push notifications require an Apple Developer account, the Push Notifications capability, and valid APNs credentials uploaded in the social.plus Console.
</Warning>

## SDK Surface

| Purpose                           | Current iOS API                                     | When to call                                                                    |
| --------------------------------- | --------------------------------------------------- | ------------------------------------------------------------------------------- |
| Register the current device token | `client.registerPushNotification(withDeviceToken:)` | After APNs returns a device token and the SDK has a signed-in user session.     |
| Unregister the current device     | `client.unregisterPushNotification()`               | On sign-out or when this installation should stop receiving push notifications. |

## Parameters

| Name    | Type     | Required | Description                                                        |
| ------- | -------- | -------- | ------------------------------------------------------------------ |
| `token` | `String` | Yes      | APNs device token converted from the `Data` value returned by iOS. |

## 1. Configure APNs

In Apple Developer Console:

1. Open **Certificates, Identifiers & Profiles**.
2. Select your app's Bundle ID.
3. Enable Push Notifications.
4. Create the APNs certificate or auth key your release process uses.

In Xcode:

1. Select your app target.
2. Open **Signing & Capabilities**.
3. Add **Push Notifications**.
4. Add background remote-notification mode only if your app needs background notification handling.

In the social.plus Console, open **Settings > Push Notifications** and upload the iOS APNs credential for the same Bundle ID.

## 2. Request System Registration

Ask the user for notification permission at a product moment that makes sense, then ask iOS to register the app for remote notifications.

<CodeGroup>
  ```swift iOS theme={null}
  import UserNotifications

  UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { granted, _ in
      if granted {
          DispatchQueue.main.async {
              UIApplication.shared.registerForRemoteNotifications()
          }
      }
  }
  ```
</CodeGroup>

## 3. Register the APNs Token

When iOS calls your app delegate with the device token, convert the token data to a hex string and pass it to the SDK.

<CodeGroup>
  ```swift iOS theme={null}
  func application(
      _ application: UIApplication,
      didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
  ) {
      let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()

      Task { @MainActor in
          do {
              try await client.registerPushNotification(withDeviceToken: token)
          } catch {
              handleError(error)
          }
      }
  }
  ```
</CodeGroup>

<Note>
  `registerPushNotification(withDeviceToken:)` is available for signed-in users. The SDK throws for guest users.
</Note>

## 4. Unregister on Sign-Out

Call unregister when the current app installation should stop receiving push notifications for the signed-in social.plus user.

<CodeGroup>
  ```swift iOS theme={null}
  try await client.unregisterPushNotification()
  ```
</CodeGroup>

## Setup Checklist

* Push Notifications capability is enabled for the app target.
* The APNs credential for the app Bundle ID is uploaded in the social.plus Console.
* The app calls `UIApplication.shared.registerForRemoteNotifications()` after permission is granted.
* The APNs device token is passed to `client.registerPushNotification(withDeviceToken:)`.
* The app calls `client.unregisterPushNotification()` on sign-out when push should stop for that user.
