Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] macOS Safari - auto resubscribe #1117

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading