more logging

This commit is contained in:
Alek Michelson 2026-04-09 23:50:36 -04:00
parent e46d983111
commit 94512211d8
2 changed files with 8 additions and 5 deletions

View file

@ -88,7 +88,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, ObservableObject {
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let token = deviceToken.map { data in String(format: "%02.2hhx", data) }.joined() let token = deviceToken.map { data in String(format: "%02.2hhx", data) }.joined()
Messaging.messaging().apnsToken = deviceToken Messaging.messaging().apnsToken = deviceToken
Log.d(tag, "Registered for remote notifications. Passing APNs token to Firebase: \(token)") Log.d(tag, "Registered for remote notifications. Passing APNs token \(token.prefix(12))... to Firebase")
} }
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
@ -166,7 +166,11 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
extension AppDelegate: MessagingDelegate { extension AppDelegate: MessagingDelegate {
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) { func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
Log.d(tag, "Firebase token received: \(String(describing: fcmToken))") if let fcmToken = fcmToken, !fcmToken.isEmpty {
Log.d(tag, "Firebase token received: \(fcmToken.prefix(12))...")
} else {
Log.w(tag, "Firebase token missing")
}
// Subscribe to ~poll topic // Subscribe to ~poll topic
Messaging.messaging().subscribe(toTopic: pollTopic) { error in Messaging.messaging().subscribe(toTopic: pollTopic) { error in

View file

@ -68,7 +68,6 @@ class NotificationService: UNNotificationServiceExtension {
private func handlePollRequest(_ request: UNNotificationRequest, _ content: UNMutableNotificationContent, _ pollRequest: Message, _ contentHandler: @escaping (UNNotificationContent) -> Void) { private func handlePollRequest(_ request: UNNotificationRequest, _ content: UNMutableNotificationContent, _ pollRequest: Message, _ contentHandler: @escaping (UNNotificationContent) -> Void) {
let subscription = store?.getSubscriptions()?.first { subscription in let subscription = store?.getSubscriptions()?.first { subscription in
// Poll requests usually target the hashed topic URL, but tolerate raw topic payloads too // Poll requests usually target the hashed topic URL, but tolerate raw topic payloads too
// Previously polls may have been ignored?
subscription.urlHash() == pollRequest.topic || subscription.topic == pollRequest.topic subscription.urlHash() == pollRequest.topic || subscription.topic == pollRequest.topic
} }
let baseUrl = subscription?.baseUrl let baseUrl = subscription?.baseUrl
@ -77,7 +76,7 @@ class NotificationService: UNNotificationServiceExtension {
let subscription = subscription, let subscription = subscription,
let baseUrl = baseUrl let baseUrl = baseUrl
else { else {
Log.w(tag, "Cannot find subscription", pollRequest) Log.w(tag, "Cannot find subscription for poll request topic=\(pollRequest.topic), pollId=\(pollRequest.pollId ?? "<nil>")")
contentHandler(request.content) contentHandler(request.content)
return return
} }
@ -87,7 +86,7 @@ class NotificationService: UNNotificationServiceExtension {
// The extension only needs contentHandler to be called from the async callback // The extension only needs contentHandler to be called from the async callback
ApiService.shared.poll(subscription: subscription, messageId: pollId, user: user) { message, error in ApiService.shared.poll(subscription: subscription, messageId: pollId, user: user) { message, error in
guard let message = message else { guard let message = message else {
Log.w(self.tag, "Error fetching message", error) Log.w(self.tag, "Error fetching poll request message topic=\(pollRequest.topic), pollId=\(pollId), subscription=\(subscription.urlString())", error)
contentHandler(request.content) contentHandler(request.content)
return return
} }