From 77c7b822931ac9b7565cc93740dc7f58d21f96e0 Mon Sep 17 00:00:00 2001 From: Justin Hernandez Date: Sun, 29 Jun 2025 22:58:46 -0700 Subject: [PATCH] SEL-472: Enable production push notifications (#703) * chore: leave sandbox apns token comment * tweak entitlement * coderabbit ai feedback * firebase tweaks --- app/firebase.json | 6 +++ app/ios/OpenPassport/AppDelegate.mm | 40 ++++++++++++------- .../OpenPassport/OpenPassport.entitlements | 4 +- 3 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 app/firebase.json diff --git a/app/firebase.json b/app/firebase.json new file mode 100644 index 000000000..78d61b10c --- /dev/null +++ b/app/firebase.json @@ -0,0 +1,6 @@ +{ + "react-native": { + "messaging_auto_init_enabled": true, + "messaging_ios_auto_register_for_remote_messages": true + } +} diff --git a/app/ios/OpenPassport/AppDelegate.mm b/app/ios/OpenPassport/AppDelegate.mm index e626938aa..60288c9e4 100644 --- a/app/ios/OpenPassport/AppDelegate.mm +++ b/app/ios/OpenPassport/AppDelegate.mm @@ -15,21 +15,28 @@ { [FIRApp configure]; - // TODO: Uncomment this after the APN has been configured - // if ([UNUserNotificationCenter class] != nil) { - // UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; - // center.delegate = self; + if ([UNUserNotificationCenter class] != nil) { + UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; + center.delegate = self; - // // Request permission for notifications - // [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) - // completionHandler:^(BOOL granted, NSError * _Nullable error) { - // if (granted) { - // dispatch_async(dispatch_get_main_queue(), ^{ - // [[UIApplication sharedApplication] registerForRemoteNotifications]; - // }); - // } - // }]; - // } + // Request permission for notifications + [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) + completionHandler:^(BOOL granted, NSError * _Nullable error) { + if (error) { + NSLog(@"Failed to request notification authorization: %@", error.localizedDescription); + return; + } + + if (granted) { + NSLog(@"Notification authorization granted"); + dispatch_async(dispatch_get_main_queue(), ^{ + [[UIApplication sharedApplication] registerForRemoteNotifications]; + }); + } else { + NSLog(@"Notification authorization denied by user"); + } + }]; + } self.moduleName = @"OpenPassport"; self.initialProps = @{}; @@ -65,7 +72,12 @@ continueUserActivity:(NSUserActivity *)userActivity { NSString *token = [self stringFromDeviceToken:deviceToken]; NSLog(@"APNs device token: %@", token); + +#ifdef DEBUG + [[FIRMessaging messaging] setAPNSToken:deviceToken type:FIRMessagingAPNSTokenTypeSandbox]; +#else [[FIRMessaging messaging] setAPNSToken:deviceToken type:FIRMessagingAPNSTokenTypeProd]; +#endif } // Handle device token registration errors diff --git a/app/ios/OpenPassport/OpenPassport.entitlements b/app/ios/OpenPassport/OpenPassport.entitlements index be4b119cb..1e81c4e00 100644 --- a/app/ios/OpenPassport/OpenPassport.entitlements +++ b/app/ios/OpenPassport/OpenPassport.entitlements @@ -2,8 +2,8 @@ - aps-environment - development + aps-environment + production com.apple.developer.associated-appclip-app-identifiers 5B29R5LYHQ.com.warroom.proofofpassport.Clip