Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 730cab7

Browse files
Push Notifications with Vue #982
1 parent a3bd6e8 commit 730cab7

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/firebase.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ export function registerForInteractivePush(model: any): void;
873873

874874
export function getCurrentPushToken(): Promise<string>;
875875

876-
export function registerForPushNotifications(): Promise<void>;
876+
export function registerForPushNotifications(options?: MessagingOptions): Promise<void>;
877877

878878
export function unregisterForPushNotifications(): Promise<void>;
879879

src/messaging/messaging.ios.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export function registerForPushNotifications(options?: MessagingOptions): Promis
9090
}
9191
});
9292
}
93+
9394
export function unregisterForPushNotifications(): Promise<void> {
9495
return new Promise((resolve, reject) => {
9596
try {
@@ -152,15 +153,19 @@ export function addOnPushTokenReceivedCallback(callback) {
152153
}
153154

154155
export function addBackgroundRemoteNotificationHandler(appDelegate) {
155-
if (typeof (FIRMessaging) === "undefined") {
156-
appDelegate.prototype.applicationDidRegisterForRemoteNotificationsWithDeviceToken = (application: UIApplication, deviceToken: NSData) => {
156+
appDelegate.prototype.applicationDidRegisterForRemoteNotificationsWithDeviceToken = (application: UIApplication, deviceToken: NSData) => {
157+
if (typeof (FIRMessaging) !== "undefined") {
158+
// make sure Firebase has the latest APNs token (issue #982)
159+
FIRMessaging.messaging().APNSToken = deviceToken;
160+
} else {
161+
// if Firebase Messaging isn't used, the developer cares about the APNs token, so pass it to the app
157162
const token = deviceToken.description.replace(/[< >]/g, "");
158163
_pushToken = token;
159164
if (_receivedPushTokenCallback) {
160165
_receivedPushTokenCallback(token);
161166
}
162-
};
163-
}
167+
}
168+
};
164169

165170
appDelegate.prototype.applicationDidReceiveRemoteNotificationFetchCompletionHandler = (app, notification, completionHandler) => {
166171
// Pass notification to auth and check if they can handle it (in case phone auth is being used), see https://firebase.google.com/docs/auth/ios/phone-auth
@@ -561,9 +566,9 @@ class UNUserNotificationCenterDelegateImpl extends NSObject implements UNUserNot
561566
const userInfoJSON = firebaseUtils.toJsObject(userInfo);
562567

563568
if (_showNotificationsWhenInForeground || // Default value, in case we always want to show when in foreground.
564-
userInfoJSON["gcm.notification.showWhenInForeground"] === "true" || // This is for FCM, ...
565-
userInfoJSON["showWhenInForeground"] === true || // ...this is for non-FCM...
566-
(userInfoJSON.aps && userInfoJSON.aps.showWhenInForeground === true) // ...and this as well (so users can choose where to put it).
569+
userInfoJSON["gcm.notification.showWhenInForeground"] === "true" || // This is for FCM, ...
570+
userInfoJSON["showWhenInForeground"] === true || // ...this is for non-FCM...
571+
(userInfoJSON.aps && userInfoJSON.aps.showWhenInForeground === true) // ...and this as well (so users can choose where to put it).
567572
) {
568573
// don't invoke the callback here, since the app shouldn't fi. navigate to a new page unless the user pressed the notification
569574
completionHandler(UNNotificationPresentationOptions.Alert | UNNotificationPresentationOptions.Sound | UNNotificationPresentationOptions.Badge);

0 commit comments

Comments
 (0)