Flutter app for iOS crashes on startup with Secondary Firebase app #4879
-
I have a Flutter app, in which I tried to initialise a secondary app using the code given in the docs: await Firebase.initializeApp(
name: 'SecondaryApp',
options: const FirebaseOptions(
appId: 'my_appId',
apiKey: 'my_apiKey',
messagingSenderId: 'my_messagingSenderId',
projectId: 'my_projectId'
)
); It works on Android, but on iOS (iPhone 6S), the app keeps crashing on startup. Is there something that I am missing? Here's the code of the dart file where I am initialising the Firebase apps: import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
class FirebaseInitialisationScreen extends StatelessWidget {
Future _initialiseFirebase() async {
await Firebase.initializeApp();
List<String> appNames = Firebase.apps.map((app) {
return app.name;
}).toList();
// if statement to make sure that the secondary app does not get initialised again
if (!appNames.contains('SecondaryApp')) {
await Firebase.initializeApp(
name: 'SecondaryApp',
options: FirebaseOptions(
androidClientId: '...',
apiKey: '...',
appId: '...',
messagingSenderId: '...',
projectId: '...',
iosBundleId: '...',
iosClientId: '...',
),
);
}
}
@override
Widget build(BuildContext context) {
return FutureBuilder(
// Initialize FlutterFire:
future: _initialiseFirebase(),
builder: (context, snapshot) {
// Check for errors
if (snapshot.hasError) {
return Scaffold(
body: Center(
child: Text('Something went wrong! :('),
),
);
}
// Once complete, show your application
if (snapshot.connectionState == ConnectionState.done) {
print('Initialisation done!');
return MainScreen();
}
// Otherwise, show something whilst waiting for initialization to complete
return Scaffold(
body: Center(
child: CircularProgressIndicator(),
),
);
},
);
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I found the solution. I was using the wrong I am not sure how to close a discussion on Github. Closes #4879 |
Beta Was this translation helpful? Give feedback.
-
The reason for crashing on iOS is the AppID , it's different for ios and android. in flutter we define appid for both . |
Beta Was this translation helpful? Give feedback.
I found the solution. I was using the wrong
appId
.I am not sure how to close a discussion on Github. Closes #4879