Browse Source

fix: APNS token ids are lowercase ASCII (#46150)

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <[email protected]>
trop[bot] 1 month ago
parent
commit
f008b0d0b2

+ 3 - 0
docs/api/push-notifications.md

@@ -46,4 +46,7 @@ See: https://developer.apple.com/documentation/appkit/nsapplication/1428476-regi
 ### `pushNotifications.unregisterForAPNSNotifications()` _macOS_
 
 Unregisters the app from notifications received from APNS.
+
+Apps unregistered through this method can always reregister.
+
 See: https://developer.apple.com/documentation/appkit/nsapplication/1428747-unregisterforremotenotifications?language=objc

+ 3 - 8
shell/browser/api/electron_api_push_notifications_mac.mm

@@ -19,10 +19,7 @@ v8::Local<v8::Promise> PushNotifications::RegisterForAPNSNotifications(
   gin_helper::Promise<std::string> promise(isolate);
   v8::Local<v8::Promise> handle = promise.GetHandle();
 
-  [[AtomApplication sharedApplication]
-      registerForRemoteNotificationTypes:NSRemoteNotificationTypeBadge |
-                                         NSRemoteNotificationTypeAlert |
-                                         NSRemoteNotificationTypeSound];
+  [[AtomApplication sharedApplication] registerForRemoteNotifications];
 
   PushNotifications::apns_promise_set_.emplace_back(std::move(promise));
   return handle;
@@ -30,8 +27,7 @@ v8::Local<v8::Promise> PushNotifications::RegisterForAPNSNotifications(
 
 void PushNotifications::ResolveAPNSPromiseSetWithToken(
     const std::string& token_string) {
-  std::vector<gin_helper::Promise<std::string>> promises =
-      std::move(PushNotifications::apns_promise_set_);
+  auto promises = std::move(PushNotifications::apns_promise_set_);
   for (auto& promise : promises) {
     promise.Resolve(token_string);
   }
@@ -39,8 +35,7 @@ void PushNotifications::ResolveAPNSPromiseSetWithToken(
 
 void PushNotifications::RejectAPNSPromiseSetWithError(
     const std::string& error_message) {
-  std::vector<gin_helper::Promise<std::string>> promises =
-      std::move(PushNotifications::apns_promise_set_);
+  auto promises = std::move(PushNotifications::apns_promise_set_);
   for (auto& promise : promises) {
     promise.RejectWithErrorMessage(error_message);
   }

+ 3 - 1
shell/browser/mac/electron_application_delegate.mm

@@ -180,8 +180,10 @@ static NSDictionary* UNNotificationResponseToNSDictionary(
     didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {
   // Resolve outstanding APNS promises created during registration attempts
   if (auto* push_notifications = electron::api::PushNotifications::Get()) {
+    std::string encoded =
+        base::HexEncode(electron::util::as_byte_span(deviceToken));
     push_notifications->ResolveAPNSPromiseSetWithToken(
-        base::HexEncode(electron::util::as_byte_span(deviceToken)));
+        base::ToLowerASCII(encoded));
   }
 }