diff --git a/docs/api/push-notifications.md b/docs/api/push-notifications.md index 01c0e830e5b8..099689d92730 100644 --- a/docs/api/push-notifications.md +++ b/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 diff --git a/shell/browser/api/electron_api_push_notifications_mac.mm b/shell/browser/api/electron_api_push_notifications_mac.mm index b9f3de17441a..ede147f28b4e 100644 --- a/shell/browser/api/electron_api_push_notifications_mac.mm +++ b/shell/browser/api/electron_api_push_notifications_mac.mm @@ -19,10 +19,7 @@ v8::Local PushNotifications::RegisterForAPNSNotifications( gin_helper::Promise promise(isolate); v8::Local 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 PushNotifications::RegisterForAPNSNotifications( void PushNotifications::ResolveAPNSPromiseSetWithToken( const std::string& token_string) { - std::vector> 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> promises = - std::move(PushNotifications::apns_promise_set_); + auto promises = std::move(PushNotifications::apns_promise_set_); for (auto& promise : promises) { promise.RejectWithErrorMessage(error_message); } diff --git a/shell/browser/mac/electron_application_delegate.mm b/shell/browser/mac/electron_application_delegate.mm index 007cff291e1b..72774bcd6783 100644 --- a/shell/browser/mac/electron_application_delegate.mm +++ b/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)); } }