firebase.notifications().getInitialNotification() returns null in iOS - firebase

I have a React Native project and I'm using Firebase, thus using react-native-firebase npm package in my project to be able to handle push notifications. I followed the docs here. All seems fine so far except that getInitialNotification() function which keeps giving me null in iOS. Therefore, I can't check if the app is opened by notification tap. Everything works like a charm in Android though.
Any suggestions?
async componentDidMount() {
const notificationOpen: NotificationOpen = await firebase.notifications().getInitialNotification();
console.log(notificationOpen); // Outputs null
}
SOLVED
I solved the issue by using latest react-native (0.59.9 > 0.60.5) and react-native-firebase (5.5.4 > 5.5.6) versions.

Related

NgRx store runtime check NgZone failing on android

We implemented a network check as a side effect with window event online and offline.
online$ = createEffect(() => {
return fromEvent(window, 'online').pipe(mapTo(NetworkActions.deviceOnline()));
});
This works fine in Desktop Chrome and on iOS Safari but somehow results in a strictActionWithinNgZone runtime check on Android:
{
"state": {
"keyboard": {
"isKeyboardOpen": false
},
"network": {
"isDeviceOnline": true
}
},
"error": "Error: Action '[Network] Device Online' running outside NgZone. https://ngrx.io/guide/store/configuration/runtime-checks#strictactionwithinngzone"
},
Does anybody have any idea why this only happens in Android and why it even is a problem to begin with?
Edit:
As far as I understand it, fromEvent(window, '...') should always be inside the zone because zone.js does patch all Browser EventTarget.
Also this is on an Ionic + Cordova App but only when built on Android. Only reason I could see for the difference could be in the Webview it is running in but other than that it is just basic RxJS and Angular
Thanks Pascal
It looks like this was a super specific problem with an Ionic + Cordova App and the Cordova Network Plugin https://ionicframework.com/docs/native/network
This seems to interfere with the Android Platform. Without the Plugins the Error does not occur but the online and offline window events also never fire on Android. So I guess this has nothing to do with NgRx.

firestore is not working with React Native Expo

I installed firebase with react native expo using expo add firebase, then
I created a file (firebase.tsx) and added the Firebase configuration and initialized the app like in this screenshot with correct values].
I have added the google-services.json and
GoogleService-info.plist to the root of my expo project like the documentation say and i am importing firebase in my api service like this import Firebase from './../../../firebase'.
In my register function I call the firebase create user function
const response = await Firebase.auth().createUserWithEmailAndPassword(values.email.value, values.password.value)
The response is never returned, and if I use . then nothing happens either.
If I log firebase.auth I get an object with my API key and app name, etc. so Firebase is installed, but whenever I call the database for sign in or to access a collection nothing happens.
This is my package.json.
This is my app.json.
I added bundleIdentifier and googleServicesFile to iOS and package and googleServicesFile for Android.
currently Firebase seems not to be working in expo if you are using the android configuration. I have tried the web configuration and it has worked for me. Here is the youtube tutorial for it. Watch from 38:20 to set up.

C++ exception in 'nativeFlushQueueImmediate' when trying to access firebase on react native

I'm using https://rnfirebase.io in react native, and I'm getting this strange error when trying to call firebase sign in with phone
submit() {
firebase
.auth()
.signInWithPhoneNumber(this.phoneInput)
.then(confirmResult => console.log(confirmResult))
.catch(error => console.log(error));
}
What could it be?
This can happen when you've updated a native dependancy via npm but have not rebuilt the native side of your app.
The JS bundle will generally have the latest code immediately (after packager restart) but the native side will not until you rebuild your app on xcode/studio; therefore causing argument mismatches across React Native's bridge as both could be expecting very different arguments based on their previous versions.
The same applies in reverse, you've re-built your native app but not restarted the packager after updating a native dependancy via npm.

Firebase App named DEFAULT already exist [duplicate]

Just loaded firebase 3.0 with react-native and getting the error
[fatal][tid:com.facebook.react.RCTExceptionsManagerQueue] Unhandled
JS Exception: Can't find variable: document
Is react-native supported yet?
React-native code:
var firebase = require('firebase')
// Initialize Firebase
var config = {
apiKey: '<apiKey>',
authDomain: '<app>.firebaseapp.com',
databaseURL: 'https://<app>.firebaseio.com',
storageBucket: 'firebase-<app>.appspot.com'
};
firebase.config(config)
The newest version of firebase uses the document variables that are used in web applications and the RCTWebSocket or RCTView doesn't work the same way. (I'm not 100% sure about all the details). Anyway, you can just install an older version of firebase and it will work for you. Assuming you have npm installed follow these instructions.
Uninstall Firebase from your react-native project npm uninstall firebase --save
Install version 2.4.2 of firebase npm install firebase#2.4.2 --save
Happy Firebaseing!
Firebase JS SDK 3.1 just got released and is now compatible with React Native!
See release notes.
I was able to get Firebase 3.0.2 to load in React Native by putting the following in a .js file and importing it at the top of index.ios.js:
global.location = {
href: ''
};
global.screen = {
};
global.document = {
getElementsByTagName: function(){}
};
global.parent = global;
There may be other gotchas - I have not explored further than this but it might get Firebase 3 working for you.
Firebase 3.x is not supported in RN (yet..).
Issue
I think the issue relates to the auth module's dependency on the browser's window variable.
Will it be officially supported?
According to the following discussion thread from the Firebase team, they are presently working on 3.x support. There is however no release time frame set.
Google Groups Discussion.
Workarounds
Option 1 (with FB 2.x)
From Jacob Wenger:
If React Native support is a blocker for you, please continue to use
the 2.x.x SDKs until we resolve this issue. The 2.x.x SDKs will
continue to work, even after you migrate to the new console..`
Option 2 (with FB 3.x)
From Jacob Wenger:
As a "workaround" if you don't need auth (unlikely, I know, but still
worth mentioning), you should be able to do the following:
var app = require('firebase/app');
var database = require('firebase/database');
To use last version of Firebase with ReactNative you can use Firebase Bridge.
I have a demo app here.
Whilst the Firebase JS SDK does work on react native now, it is mainly built for the web and is generally not the best solution for react-native.
The Firebase Web SDK runs entirely on react native's JS thread, therefore affecting your application frame rate (the link explains this well).
In my tests, the native firebase SDK's has been roughly 2-3 times quicker than using the web SDK.
But on top of the potential performance impacts there's a lot of features you'll be unable to use with the web SDK on android/ios devices. For example:
Notifications / FCM
Offline capabilities
Storage upload/download
Firebase Crash Reporting
Analytics
Use of social authentication providers
The best approach would be to run with the native android/ios firebase sdk's and have a bridge between them and your js code (i.e. a native module setup).
Thankfully you don't have to implement this yourself, there's already modules out there to do this for you:
react-native-firebase for example mirrors the the web sdk's api js side but executes on the native side using the native android & ios firebase sdk's. It's fully compatible with any existing firebase js logic that you may have already implemented and is intended as a drop in replacement for the web sdk.
(disclaimer: I am the author of react-native-firebase)

Error when running Firebase 3.0 with React Native

Just loaded firebase 3.0 with react-native and getting the error
[fatal][tid:com.facebook.react.RCTExceptionsManagerQueue] Unhandled
JS Exception: Can't find variable: document
Is react-native supported yet?
React-native code:
var firebase = require('firebase')
// Initialize Firebase
var config = {
apiKey: '<apiKey>',
authDomain: '<app>.firebaseapp.com',
databaseURL: 'https://<app>.firebaseio.com',
storageBucket: 'firebase-<app>.appspot.com'
};
firebase.config(config)
The newest version of firebase uses the document variables that are used in web applications and the RCTWebSocket or RCTView doesn't work the same way. (I'm not 100% sure about all the details). Anyway, you can just install an older version of firebase and it will work for you. Assuming you have npm installed follow these instructions.
Uninstall Firebase from your react-native project npm uninstall firebase --save
Install version 2.4.2 of firebase npm install firebase#2.4.2 --save
Happy Firebaseing!
Firebase JS SDK 3.1 just got released and is now compatible with React Native!
See release notes.
I was able to get Firebase 3.0.2 to load in React Native by putting the following in a .js file and importing it at the top of index.ios.js:
global.location = {
href: ''
};
global.screen = {
};
global.document = {
getElementsByTagName: function(){}
};
global.parent = global;
There may be other gotchas - I have not explored further than this but it might get Firebase 3 working for you.
Firebase 3.x is not supported in RN (yet..).
Issue
I think the issue relates to the auth module's dependency on the browser's window variable.
Will it be officially supported?
According to the following discussion thread from the Firebase team, they are presently working on 3.x support. There is however no release time frame set.
Google Groups Discussion.
Workarounds
Option 1 (with FB 2.x)
From Jacob Wenger:
If React Native support is a blocker for you, please continue to use
the 2.x.x SDKs until we resolve this issue. The 2.x.x SDKs will
continue to work, even after you migrate to the new console..`
Option 2 (with FB 3.x)
From Jacob Wenger:
As a "workaround" if you don't need auth (unlikely, I know, but still
worth mentioning), you should be able to do the following:
var app = require('firebase/app');
var database = require('firebase/database');
To use last version of Firebase with ReactNative you can use Firebase Bridge.
I have a demo app here.
Whilst the Firebase JS SDK does work on react native now, it is mainly built for the web and is generally not the best solution for react-native.
The Firebase Web SDK runs entirely on react native's JS thread, therefore affecting your application frame rate (the link explains this well).
In my tests, the native firebase SDK's has been roughly 2-3 times quicker than using the web SDK.
But on top of the potential performance impacts there's a lot of features you'll be unable to use with the web SDK on android/ios devices. For example:
Notifications / FCM
Offline capabilities
Storage upload/download
Firebase Crash Reporting
Analytics
Use of social authentication providers
The best approach would be to run with the native android/ios firebase sdk's and have a bridge between them and your js code (i.e. a native module setup).
Thankfully you don't have to implement this yourself, there's already modules out there to do this for you:
react-native-firebase for example mirrors the the web sdk's api js side but executes on the native side using the native android & ios firebase sdk's. It's fully compatible with any existing firebase js logic that you may have already implemented and is intended as a drop in replacement for the web sdk.
(disclaimer: I am the author of react-native-firebase)

Resources