Skip to content

Commit 4514030

Browse files
authored
Merge pull request #1117 from OneSignal/fix/safari-auto-resubscribe
[Fix] macOS Safari auto resubscribe
2 parents 5754813 + cb01847 commit 4514030

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

src/shared/managers/SubscriptionManager.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -401,23 +401,29 @@ export class SubscriptionManager {
401401

402402
const { deviceToken: existingDeviceToken } =
403403
window.safari.pushNotification.permission(this.config.safariWebId);
404-
if (!existingDeviceToken) {
405-
/*
406-
We're about to show the Safari native permission request. It can fail for a number of
407-
reasons, e.g.:
408-
- Setup-related reasons when developers just starting to get set up
409-
- Address bar URL doesn't match safari certificate allowed origins (case-sensitive)
410-
- Safari web ID doesn't match provided web ID
411-
- Browsing in a Safari private window
412-
- Bad icon DPI
413-
414-
but shouldn't fail for sites that have already gotten Safari working.
415-
416-
We'll show the permissionPromptDisplay event if the Safari user isn't already subscribed,
417-
otherwise an already subscribed Safari user would not see the permission request again.
418-
*/
419-
OneSignalEvent.trigger(OneSignal.EVENTS.PERMISSION_PROMPT_DISPLAYED);
404+
405+
if (existingDeviceToken) {
406+
pushSubscriptionDetails.setFromSafariSubscription(
407+
existingDeviceToken.toLowerCase(),
408+
);
409+
return pushSubscriptionDetails;
420410
}
411+
412+
/*
413+
We're about to show the Safari native permission request. It can fail for a number of
414+
reasons, e.g.:
415+
- Setup-related reasons when developers just starting to get set up
416+
- Address bar URL doesn't match safari certificate allowed origins (case-sensitive)
417+
- Safari web ID doesn't match provided web ID
418+
- Browsing in a Safari private window
419+
- Bad icon DPI
420+
421+
but shouldn't fail for sites that have already gotten Safari working.
422+
423+
We'll show the permissionPromptDisplay event if the Safari user isn't already subscribed,
424+
otherwise an already subscribed Safari user would not see the permission request again.
425+
*/
426+
OneSignalEvent.trigger(OneSignal.EVENTS.PERMISSION_PROMPT_DISPLAYED);
421427
const deviceToken = await this.subscribeSafariPromptPermission();
422428
PermissionUtils.triggerNotificationPermissionChanged();
423429
if (deviceToken) {

0 commit comments

Comments
 (0)