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

Commit fd80ddb

Browse files
#105 Firebase was unable to connect to FCM
1 parent 1c17507 commit fd80ddb

File tree

4 files changed

+55
-31
lines changed

4 files changed

+55
-31
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
<img src="docs/images/firebase-logo.png" width="116px" height="32px" alt="Firebase"/>
22

3+
## 3.5.2 (2016, August 20)
4+
5+
[Full changelog](https://github.com/EddyVerbruggen/nativescript-plugin-firebase/compare/3.5.1...3.5.2)
6+
7+
### SDK versions
8+
If version numbers changed clean your platform folders to avoid build errors.
9+
10+
- __iOS: 3.4.x__
11+
- Android: 9.4.0
12+
13+
### New
14+
- [#104](#104) Swap authentiction to a different Google account
15+
16+
### Fixes
17+
- [#105](#105) Receiving notifications from FCM on iOS may work better now
18+
19+
20+
321
## 3.5.1 (2016, August 12)
422

523
[Full changelog](https://github.com/EddyVerbruggen/nativescript-plugin-firebase/compare/3.5.0...3.5.1)

firebase.ios.js

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ firebase.addAppDelegateMethods = function(appDelegate) {
5757

5858
// making this conditional to avoid http://stackoverflow.com/questions/37428539/firebase-causes-issue-missing-push-notification-entitlement-after-delivery-to ?
5959
if (typeof(FIRMessaging) !== "undefined") {
60+
appDelegate.prototype.applicationDidRegisterForRemoteNotificationsWithDeviceToken = function (application, devToken) {
61+
// TODO guard with _messagingConnected ?
62+
FIRInstanceID.instanceID().setAPNSTokenType(devToken, FIRInstanceIDAPNSTokenTypeUnknown);
63+
FIRMessaging.messaging().connectWithCompletion(function(error) {
64+
if (!error) {
65+
firebase._messagingConnected = true;
66+
}
67+
});
68+
};
69+
6070
appDelegate.prototype.applicationDidReceiveRemoteNotificationFetchCompletionHandler = function (application, userInfo, completionHandler) {
6171
completionHandler(UIBackgroundFetchResultNewData);
6272
var userInfoJSON = firebase.toJsObject(userInfo);
@@ -124,16 +134,39 @@ firebase._processPendingNotifications = function() {
124134
firebase._receivedNotificationCallback(userInfoJSON);
125135
}
126136
firebase._pendingNotifications = [];
127-
firebase._addObserver(kFIRInstanceIDTokenRefreshNotification, firebase._onTokenRefreshNotification);
128137
UIApplication.sharedApplication().applicationIconBadgeNumber = 0;
129138
}
130139
};
131140

141+
firebase._onTokenRefreshNotification = function (notification) {
142+
var token = FIRInstanceID.instanceID().token();
143+
if (token === null) {
144+
return;
145+
}
146+
147+
console.log("Firebase FCM token received: " + token);
148+
149+
if (firebase._receivedPushTokenCallback) {
150+
firebase._receivedPushTokenCallback(token);
151+
}
152+
153+
FIRMessaging.messaging().connectWithCompletion(function(error) {
154+
if (error) {
155+
// this is not fatal and it scares the hell out of ppl so not logging it
156+
// console.log("Firebase was unable to connect to FCM. Error: " + error);
157+
} else {
158+
firebase._messagingConnected = true;
159+
}
160+
});
161+
};
162+
132163
// rather than hijacking the appDelegate for these we'll be a good citizen and listen to the notifications
133164
(function () {
134165

135166
if (typeof(FIRMessaging) !== "undefined") {
136167

168+
firebase._addObserver(kFIRInstanceIDTokenRefreshNotification, firebase._onTokenRefreshNotification);
169+
137170
firebase._addObserver(UIApplicationDidFinishLaunchingNotification, function (appNotification) {
138171
var notificationTypes = UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationActivationModeBackground;
139172
var notificationSettings = UIUserNotificationSettings.settingsForTypesCategories(notificationTypes, null);
@@ -161,9 +194,7 @@ firebase._processPendingNotifications = function() {
161194
// Firebase notifications (FCM)
162195
if (firebase._messagingConnected !== null) {
163196
FIRMessaging.messaging().connectWithCompletion(function(error) {
164-
if (error) {
165-
console.log("Firebase was unable to connect to FCM. Error: " + error);
166-
} else {
197+
if (!error) {
167198
firebase._messagingConnected = true;
168199
}
169200
});
@@ -308,12 +339,9 @@ firebase.init = function (arg) {
308339

309340
// Firebase notifications (FCM)
310341
if (typeof(FIRMessaging) !== "undefined") {
311-
firebase._addObserver(kFIRInstanceIDTokenRefreshNotification, firebase._onTokenRefreshNotification);
312-
313342
if (arg.onMessageReceivedCallback !== undefined) {
314343
firebase.addOnMessageReceivedCallback(arg.onMessageReceivedCallback);
315344
}
316-
317345
if (arg.onPushTokenReceivedCallback !== undefined) {
318346
firebase.addOnPushTokenReceivedCallback(arg.onPushTokenReceivedCallback);
319347
}
@@ -336,28 +364,6 @@ firebase.init = function (arg) {
336364
});
337365
};
338366

339-
firebase._onTokenRefreshNotification = function (notification) {
340-
var token = FIRInstanceID.instanceID().token();
341-
if (token === null) {
342-
return;
343-
}
344-
345-
console.log("Firebase FCM token received: " + token);
346-
347-
if (firebase._receivedPushTokenCallback) {
348-
firebase._receivedPushTokenCallback(token);
349-
}
350-
351-
FIRMessaging.messaging().connectWithCompletion(function(error) {
352-
if (error) {
353-
// this is not fatal at all but still would like to know how often this happens
354-
console.log("Firebase was unable to connect to FCM. Error: " + error);
355-
} else {
356-
firebase._messagingConnected = true;
357-
}
358-
});
359-
};
360-
361367
firebase.getRemoteConfig = function (arg) {
362368
return new Promise(function (resolve, reject) {
363369
try {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-plugin-firebase",
3-
"version": "3.5.2-dev",
3+
"version": "3.5.2",
44
"description" : "Fire. Base. Firebase!",
55
"main" : "firebase.js",
66
"nativescript": {

platforms/ios/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
pod 'Firebase', '~> 3.3.0'
2+
pod 'Firebase', '~> 3.4.0'
33
pod 'Firebase/Database'
44
pod 'Firebase/Auth'
55
pod 'Firebase/Crash'

0 commit comments

Comments
 (0)