Skip to main content

iOS Push Notifications

The Alogame SDK uses Apple Push Notification service (APNs) for push notifications. Firebase Messaging is optional — the SDK works with raw APNs tokens and only bridges to Firebase if your project includes it.

Step 1 — Enable Push Notifications capability in Xcode​

  1. Open your project in Xcode → select the app target.
  2. Go to Signing & Capabilities tab.
  3. Click + Capability → add Push Notifications.
  4. Also add Background Modes → check Remote notifications.
Target → Signing & Capabilities
├── Push Notifications ← required
└── Background Modes
└── ✓ Remote notifications ← required for background push delivery

Without "Push Notifications" capability, APNs registration will silently fail. Without "Remote notifications" background mode, push will only work when the app is in foreground.

Step 2 — (Optional) Add GoogleService-Info.plist for Firebase​

Firebase is not required for push to work. APNs tokens are sent directly to the Alogame backend.

If your project uses Firebase (e.g. for analytics or other Firebase services):

  1. Open Firebase Console → your project.
  2. Go to Project settings → Your apps → iOS.
  3. Register your app with your Bundle ID.
  4. Download GoogleService-Info.plist.
  5. Add it to your Xcode project (drag into the project navigator, check Add to target).

When GoogleService-Info.plist is present and FirebaseMessaging is linked, the SDK automatically bridges the APNs token to Firebase and uses the FCM token for backend registration.

Step 3 — Forward AppDelegate callbacks​

This is covered in the Installation guide but included here for completeness.

Swift (UIKit AppDelegate)​

AppDelegate.swift
import OegSdkV2

class AppDelegate: NSObject, UIApplicationDelegate {

func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
OEGManager.handleDidFinishLaunching(options: launchOptions)
return true
}

// APNs registration success — forward device token to SDK
func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
OEGManager.handleDidRegisterForRemoteNotifications(deviceToken: deviceToken)
}

// APNs registration failure — optional logging
func application(
_ application: UIApplication,
didFailToRegisterForRemoteNotificationsWithError error: Error
) {
print("[OEGPush] APNs registration failed: \(error)")
}

// Background push delivery
func application(
_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void
) {
OEGManager.handleRemoteNotification(userInfo)
completionHandler(.newData)
}
}

Objective-C (UIKit AppDelegate)​

AppDelegate.mm
#import <OegSdkV2/OegSdkV2-Swift.h>

- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[OEGManager handleDidRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}

- (void)application:(UIApplication *)application
didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"[OEGPush] APNs registration failed: %@", error);
}

- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[OEGManager handleRemoteNotification:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
}

SwiftUI app (no UIKit AppDelegate)​

MyApp.swift
import SwiftUI
import OegSdkV2

@main
struct MyApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
// AppDelegate class above handles the callbacks
}

Step 4 — Request permission and register​

The SDK does not automatically request push permission or call registerForRemoteNotifications. Your game controls when the prompt appears.

Call this at an appropriate moment — after tutorial, at game login, or on a dedicated settings screen:

Swift
// 1. Request user permission (shows the system prompt once)
OEGPush.shared.requestAuthorization { granted, error in
guard granted else { return }

// 2. Register with APNs to get a device token
OEGPush.shared.registerForPushNotifications(application: UIApplication.shared)
// └── internally calls UIApplication.shared.registerForRemoteNotifications()
// └── triggers AppDelegate.didRegisterForRemoteNotificationsWithDeviceToken
// └── SDK forwards the token to the OEG backend after next login
}
Objective-C
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert |
UNAuthorizationOptionSound |
UNAuthorizationOptionBadge)
completionHandler:^(BOOL granted, NSError *error) {
if (granted) {
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] registerForRemoteNotifications];
});
}
}];

The system only shows the permission prompt once. If denied, the user must re-enable in Settings. Always explain the value of push before calling requestAuthorization.

Step 5 — Handle foreground notifications​

By default iOS suppresses push banners while the app is in foreground. Wire the UNUserNotificationCenterDelegate to show them:

Swift
import UserNotifications
import OegSdkV2

// Set delegate early — before any notifications can arrive
UNUserNotificationCenter.current().delegate = OEGPush.shared

// OEGPush.shared already implements UNUserNotificationCenterDelegate.
// It shows .alert + .sound + .badge and forwards the payload to your delegate.

Or forward to your own delegate after handling:

Swift (custom delegate)
extension MyPushHandler: UNUserNotificationCenterDelegate {
func userNotificationCenter(
_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
) {
// Let the SDK forward the payload first
OEGPush.shared.userNotificationCenter(
center,
willPresent: notification,
withCompletionHandler: completionHandler
)
}
}

Step 6 — Receive notification payloads in game code​

Swift
import OegSdkV2

class MyPushDelegate: OEGPushDelegate {
func oegPushDidReceiveNotification(userInfo: [AnyHashable: Any]) {
let title = userInfo["title"] as? String
let body = userInfo["body"] as? String
// Show in-game banner or navigate to a specific screen
}

func oegPushDidUpdateToken(_ token: String) {
// Optional — SDK handles re-registration automatically
}
}

// Assign the delegate
OEGPush.shared.delegate = MyPushDelegate()

Or observe via NotificationCenter (useful in SwiftUI):

Swift (NotificationCenter)
NotificationCenter.default.addObserver(
forName: .OEGPushNotificationReceived,
object: nil,
queue: .main
) { notification in
let userInfo = notification.userInfo
}

How the SDK manages push tokens​

EventWhat the SDK does
User logs inAPNs (or FCM) token synced to Alogame backend (POST v2/push/token)
APNs token registered or rotatedRaw token forwarded to the active attribution provider — Adjust or AppsFlyer, whichever the game is configured for — for uninstall tracking (automatic)
APNs token rotatesRe-synced automatically via didRegisterForRemoteNotificationsWithDeviceToken
User logs outToken deactivated on backend (DELETE v2/push/token)
User not logged in when token arrivesQueued and sent after the next successful login
Push not configured (no APNs registration)All sync operations silently skip — auth flows are never blocked

Checklist​

  • Push Notifications capability enabled in Xcode → Signing & Capabilities
  • Background Modes → Remote notifications enabled in Xcode
  • GoogleService-Info.plist added to project (optional — only if using Firebase)
  • AppDelegate.didRegisterForRemoteNotificationsWithDeviceToken forwards to OEGManager
  • AppDelegate.didReceiveRemoteNotification:fetchCompletionHandler: forwards to OEGManager
  • UNUserNotificationCenter.current().delegate = OEGPush.shared set at app launch
  • OEGPush.shared.requestAuthorization called at appropriate moment in game flow
  • OEGPush.shared.registerForPushNotifications(application:) called after permission granted
  • OEGPush.shared.delegate set if game needs to receive notification payloads