Skip to main content

Overview

To receive push notifications in your iOS app, you need to configure the necessary permissions, register for remote notifications, and handle incoming notifications.

Prerequisites

Before you can receive push notifications:
  1. Complete the iOS SDK Installation
  2. Complete the iOS SDK Configuration
  3. Configure your iOS APNs credentials in the AppPanel dashboard (see below)

Configure APNs Credentials

Before your app can receive push notifications, you need to upload your Apple Push Notification service (APNs) credentials to AppPanel.

Step 1: Create an APNs Key in Apple Developer Portal

  1. Go to Apple Developer Portal
  2. Click the + button to create a new key
  3. Enter a name for your key (e.g., “AppPanel Push Notifications”)
  4. Check Apple Push Notifications service (APNs)
  5. Click Continue, then Register
  6. Download the .p8 file - you can only download this once, so keep it safe
  7. Note your Key ID (10-character string) and Team ID (found in top right of the page)
Store your .p8 file securely. Apple only allows you to download it once. If you lose it, you’ll need to create a new key.

Step 2: Upload to AppPanel Console

  1. Log in to your AppPanel Console
  2. Navigate to your project
  3. Go to Settings ▸ Project ▸ Push Notifications
  4. Upload your .p8 file
  5. Enter your Key ID (from Step 1)
  6. Enter your Team ID (from Step 1)
  7. Click Upload Credentials
  8. If you haven’t already, navigate to general and set your apps iOS Bundle Identifier (e.g., com.yourcompany.yourapp)
You can use the same .p8 key for both development and production environments. AppPanel will automatically route notifications to the appropriate APNs environment based on your build configuration.

iOS Setup

Step 1: Enable Push Notifications Capability

In Xcode, select your app target and go to Signing & Capabilities, then click + Capability and add Push Notifications.

Step 2: Register for Remote Notifications

In your didFinishLaunchingWithOptions, register for remote notifications. You don’t need permission to get the device token:
import UIKit
import AppPanel

class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {

        #if DEBUG
        let apiKey = "pk_test_your_test_key_here"
        #else
        let apiKey = "pk_live_your_live_key_here"
        #endif
        AppPanel.configure(apiKey: apiKey)

        // Register for remote notifications (doesn't require permission)
        UIApplication.shared.registerForRemoteNotifications()

        return true
    }
}

Step 3: Handle Device Token Registration

Add these methods to your AppDelegate to handle device token registration:
func application(
    _ application: UIApplication,
    didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
    AppPanel.shared.push.setAPNsToken(deviceToken)
}

func application(
    _ application: UIApplication,
    didFailToRegisterForRemoteNotificationsWithError error: Error
) {
    print("❌ Failed to register for remote notifications: \(error)")
}
These methods go in the same AppDelegate class shown in Step 2. They work identically for both UIKit and SwiftUI apps.

Step 4: Request Permission to Display Notifications

To actually display notifications to the user, you need to request authorization. Call this method when appropriate (e.g., during onboarding or when the user opts in):
import UserNotifications

func requestNotificationPermission() {
    let center = UNUserNotificationCenter.current()
    center.requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
        if let error = error {
            print("❌ Error requesting authorization: \(error)")
            return
        }
        if granted {
            print("✅ Notification permission accepted.")
        } else {
            print("⛔ Notification permission denied.")
        }
    }
}
You can register for remote notifications and receive a device token without requesting permission from the user. However, you must call requestNotificationPermission() and get user permission before notifications will be displayed to the user.

Step 5: Implement UNUserNotificationCenterDelegate

For more control over notification presentation, add the UNUserNotificationCenterDelegate to your AppDelegate and implement these methods: First, update your AppDelegate declaration to conform to UNUserNotificationCenterDelegate:
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
    // ... existing code from Step 2
}
Then add this line in didFinishLaunchingWithOptions (right after configuring AppPanel):
// Set notification center delegate
UNUserNotificationCenter.current().delegate = self
Finally, add these delegate methods using an extension:
import UserNotifications

extension AppDelegate {
    // Called when notification is received while app is in foreground
    func userNotificationCenter(
        _ center: UNUserNotificationCenter,
        willPresent notification: UNNotification,
        withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
    ) {
        let userInfo = notification.request.content.userInfo
        // Show notification even when app is in foreground
        completionHandler([.banner, .sound, .badge])
    }

    // Called when user taps on a notification
    func userNotificationCenter(
        _ center: UNUserNotificationCenter,
        didReceive response: UNNotificationResponse,
        withCompletionHandler completionHandler: @escaping () -> Void
    ) {
        let userInfo = response.notification.request.content.userInfo
        completionHandler()
    }
}

Troubleshooting

Notifications Not Appearing

  • Check that notification permissions are granted in Settings
  • Ensure APNs certificates are properly configured in AppPanel dashboard
  • Verify the device token is being registered successfully
  • Check that your app is using the correct bundle identifier

Device Token Not Registered

  • Ensure you’re calling registerForRemoteNotifications() on the main thread
  • Check for errors in didFailToRegisterForRemoteNotificationsWithError
  • Verify your app has the Push Notifications capability enabled

Next Steps