React Native - iOS app crashes on fetching database from firebase - rnfirebase.io - ios

In the firebase database, I have only one object. And it has only one value.
In android, everything is working fine. In iOS, the app crashes on 'on' method.
Below message appears in the red screen in iOS:
undefined is not a function (this._database.native.on...)
Here is the code that I am using in componentDidMount.
componentDidMount() {
database()
.ref('/checkPlatform')
.on('value', snapshot => {
let firebaseData = snapshot.val()
this.setState({ isAndroidDisable: firebaseData.isPlatformEnabled })
});
}
Instead of the on method, I've also tried once(). But no luck.
Any help will be appreciated.

If you are getting "this._database.native.on is not a function" on ios try -
run the pod install - after adding firebase new service(database/auth ...)
terminate the metro bundler and restart it using "npx react-native start"
run "npx react-native run-ios"
This will create a new build and the error should be gone.
Ref: https://github.com/invertase/react-native-firebase/issues/3379

Related

React Native custom fonts load and display properly in simulator, but break in Expo?

I'm currently building my first iOS and Android application in React Native, but can't get any custom font files to properly display when running through Expo. All custom fonts display properly and throw no errors when the application is run with npx react-native run-ios / run-android, however running with expo start always triggers "Unrecognized font family" errors.
My current App.tsx:
export default class App extends React.Component{
state = {
fontsLoaded: false,
};
async loadFonts() {
await Font.loadAsync({
'SFPro-Regular': require('./src/assets/fonts/SFPro-Regular.ttf'),
});
this.setState({ fontsLoaded: true });
}
componentDidMount() {
this.loadFonts();
}
render() {
if (!this.state.fontsLoaded) {
return <AppLoading />;
}
return(
<View>
<Text style={{fontFamily: 'Comfortaa-Bold', fontSize: 100}}>TEST</Text>
</View>
);
}
}
The application was originally started using npx react-native init, with Expo modules later installed for quickly testing on device. I've tried countless fixes for importing fonts over the past two weeks, and nothing seems to work – any suggestions or obvious errors I'm making?

react-native-firebase (v6): App is crashing on ios when using secondary app, works fine on Android

package.json-
"#react-native-firebase/app": "8.3.1",
"#react-native-firebase/auth": "8.3.3",
"#react-native-firebase/firestore": "7.5.3",
Initialisation-
export const initGuestChatConnection = async () => {
// DEFAULT app will always be there
if (firebase.apps.length < 2) {
await firebase.initializeApp(
GUEST_CHAT_FIREBASE_CONFIG,
GUEST_CHAT_FIREBASE_CONFIG.app_name
);
}
};
Wrapper method to get secondary app instance-
export const getGuestChatFirebaseInstance = () => {
return firebase.app(GUEST_CHAT_FIREBASE_CONFIG.app_name);
};
When we try to use auth (custom signin), we get following error-
Exception '*** -[__NSDictionaryM setObject:forKeyedSubscript:]: key cannot be nil' was thrown while invoking addAuthStateListener on target RNFBAuthModule with params (
"GUEST_CHAT"
)
Our signin method-
export const signInGuestChatFirebaseInstance = token => {
return getGuestChatFirebaseInstance()
.auth()
.signInWithCustomToken(token);
};
We thought that problem is with authentication, so we skipped it and tried to directly access Firestore (by modifying Firestore Rules) but then we started getting following error-
Exception 'FirebaseApp instance may not be nil. Use FirebaseApp.app() if you'd like to use the default FirebaseApp instance.' was thrown while invoking collectionOnSnapshot on target RNFBFirestoreCollectionModule with params (
"GUEST_CHAT",
This is working fine on Android. These methods are working on ios as well for DEFAULT Firebase app but for some reason it's crashing for secondary app.
Create iOS app for the secondary project in order to make it work. Since on adding iOS app it provides GoogleService-info.plist, so extract all config related info from GoogleService-info.plist and use it to create config for initialising second app. This will make secondary app work on iOS!

connectAsync of Expo InAppPurchases always returns undefined in ios

In order to implement inAppPurchase using expo am facing some issues.am referring https://docs.expo.io/versions/latest/sdk/in-app-purchases.i followed all steps mentioned in the document.I ejected my expo for this.In my App.js i write a code to Connects to the app store.
App.js
import * as InAppPurchases from "expo-in-app-purchases";
export default class App extends React.Component {
componentDidMount = async() => {
const history = await InAppPurchases.connectAsync();
console.log("history", history); //Here it is getting undefined...
}
............
}
am getting this error in ios.am building the solution using xcode and run in real device.
what should i do?

iOS Asynchronous Unit Testing (waitForExpectations failing) in Xcode 8 / Swift 3

I'm updating my Cocoapod that I developed to use Swift 3. Before I upgraded, all of my asynchronous unit tests were working perfectly fine. But now after upgrading, every single one of them immediately fail and I have no idea why. Here is what each one is structured like:
override func setUp() {
super.setUp()
validationExpectation = expectation(description: "Validation")
}
.
.
.
func testSymbolRequest(){
_ = MyCocoapod.makeSymbolRequest(symbol: "ABC", success: { (symbolObject) in
self.validationExpectation.fulfill()
XCTAssert(true)
}) { (error) in
self.validationExpectation.fulfill()
XCTFail(error.description)
}
waitForRequestToFinish()
}
.
.
.
func waitForRequestToFinish(){
waitForExpectations(timeout: 60.0) { (error) in
if let error = error {
XCTFail(error.localizedDescription)
}
}
}
The waitForExpectations function isn't waiting at all. It immediately fails after being called. I have also confirmed that is has nothing to do with my actual networking code and the requests work perfectly fine in my Cocoapod example project. I'm using Alamofire. I don't think that's the problem but I thought it might be worth mentioning. The error message that is printed out is "unknown error".
If you are trying to test your CocoaPod that you are developing, for some reason, the default testing target that it creates makes the waitForExpectations() function not work properly for that particular testing target. I was able to get it to finally work by doing these steps in order:
Delete the current testing target
Create a new testing target
Run a pod install and make sure the pod file is updated accordingly
Following these steps, I was able to get the waitForExpectations() to finally work within my network requests.

Javascript / Native code out of sync (differing number of arguments) error

I have recently updated to ReactNativeControllers 2.03 from 1.24. I have also updated RN to 0.25. I am using a fork which only adds a Podspec file. After sorting out all the import changes in RN I am now stumped on this error:
(See also https://github.com/wix/react-native-controllers/issues/59)
RCCManager.setRootController was called with 3 arguments, but expects
2.
If you haven't changed this method yourself, this usually means that
your versions of the native code and JavaScript code are out of sync.
Updating both should make this error go away.
The code in question:
In RCCManagerModule.m:
setRootController:(NSDictionary*)layout animationType:(NSString*)animationType globalProps:(NSDictionary*)globalProps)
and in index.js:
ControllerRegistry: {
registerController: function (appKey, getControllerFunc) {
_controllerRegistry[appKey] = getControllerFunc();
},
setRootController: function (appKey, animationType = 'none', passProps = {}) {
var controller = _controllerRegistry[appKey];
if (controller === undefined) return;
var layout = controller.render();
_validateDrawerProps(layout);
RCCManager.setRootController(layout, animationType, passProps);
}
},
As is evident, both have 3 parameters.
I've killed and restarted the packager. I've cleaned the Xcode project including derived data, and deleted watchman cache with watchman watch-del-all. I've deleted my node_modules folder, done npm install and pod install.
I've rebuilt the Xcode project. Still no luck. I don't know how to debug this further.
EDIT: I also tried to clean the pod cache, updated to Cocoapods 1.01...
I have a feeling there may be a red herring here somewhere. For reference my full trace looks like this:
2016-06-10 14:15:18.179 [warn][tid:com.facebook.React.JavaScript] Warning: ReactNative.Component is deprecated. Use React.Component from the "react" package instead.
2016-06-10 14:15:18.239 JustTuner[7523:185768] Launching Couchbase Lite...
2016-06-10 14:15:19.048 JustTuner[7523:185768] Couchbase Lite url = http://adamwilsonsMBP.lan:5984/
2016-06-10 14:15:19.050 JustTuner[7523:185768] Launching Couchbase Lite...
2016-06-10 14:15:19.058 JustTuner[7523:185768] Couchbase Lite url = http://adamwilsonsMBP.lan:5984/
2016-06-10 14:15:19.538 [error][tid:main][RCTModuleMethod.m:456] RCCManager.setRootController was called with 3 arguments, but expects 2. If you haven't changed this method yourself, this usually means that your versions of the native code and JavaScript code are out of sync. Updating both should make this error go away.
After spending many hours trying to work this out, I found that there was an out of date static library libReactNativeControllers.a in build/Products/Debug-iphonesimulator.
Deleting libReactNativeControllers.a and rebuilding the project solved the issue.
It seems that the Pod static libraries are now being saved in their respective folders e.g. build/Products/Debug-iphonesimulator/ReactNativeControllers/libReactNativeControllers.a
My guess is that the recent builds were saving the static lib in the subfolder, but the linker was picking up the out-of-date one. Anyone know why this might have changed recently?
Restarting metro with resetting cache worked for me:
react-native start --reset-cache
or
npm start -- --reset-cache
Try to Clean and Rebuild the solution in XCode if it happened in react-native iOS.

Resources