Skip to content

Commit

Permalink
Merge pull request #1117 from OneSignal/fix/safari-auto-resubscribe
Browse files Browse the repository at this point in the history
[Fix] macOS Safari auto resubscribe
  • Loading branch information
jkasten2 authored Oct 19, 2023
2 parents 5754813 + cb01847 commit 4514030
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/shared/managers/SubscriptionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,23 +401,29 @@ export class SubscriptionManager {

const { deviceToken: existingDeviceToken } =
window.safari.pushNotification.permission(this.config.safariWebId);
if (!existingDeviceToken) {
/*
We're about to show the Safari native permission request. It can fail for a number of
reasons, e.g.:
- Setup-related reasons when developers just starting to get set up
- Address bar URL doesn't match safari certificate allowed origins (case-sensitive)
- Safari web ID doesn't match provided web ID
- Browsing in a Safari private window
- Bad icon DPI
but shouldn't fail for sites that have already gotten Safari working.
We'll show the permissionPromptDisplay event if the Safari user isn't already subscribed,
otherwise an already subscribed Safari user would not see the permission request again.
*/
OneSignalEvent.trigger(OneSignal.EVENTS.PERMISSION_PROMPT_DISPLAYED);

if (existingDeviceToken) {
pushSubscriptionDetails.setFromSafariSubscription(
existingDeviceToken.toLowerCase(),
);
return pushSubscriptionDetails;
}

/*
We're about to show the Safari native permission request. It can fail for a number of
reasons, e.g.:
- Setup-related reasons when developers just starting to get set up
- Address bar URL doesn't match safari certificate allowed origins (case-sensitive)
- Safari web ID doesn't match provided web ID
- Browsing in a Safari private window
- Bad icon DPI
but shouldn't fail for sites that have already gotten Safari working.
We'll show the permissionPromptDisplay event if the Safari user isn't already subscribed,
otherwise an already subscribed Safari user would not see the permission request again.
*/
OneSignalEvent.trigger(OneSignal.EVENTS.PERMISSION_PROMPT_DISPLAYED);
const deviceToken = await this.subscribeSafariPromptPermission();
PermissionUtils.triggerNotificationPermissionChanged();
if (deviceToken) {
Expand Down

0 comments on commit 4514030

Please sign in to comment.