Skip to content

[firebase_core] for iOS will not connect to Firebase #1329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
workerbee22 opened this issue Oct 30, 2019 · 8 comments
Closed

[firebase_core] for iOS will not connect to Firebase #1329

workerbee22 opened this issue Oct 30, 2019 · 8 comments
Labels
impact: customer A bug with low impact (e.g. affecting only a few customers or has a workaround). (P3) plugin: core type: bug Something isn't working

Comments

@workerbee22
Copy link

firebase_core does not work on iOS 12.x or 13.x. The app builds for iOS but any call to FirebaseApp.allApps() returns null .... always. Works fine on Android but not iOS, will not connect to Firebase iOS app.

Example code on a brand new template Flutter project. Using firebase_core 0.4.0+9 and created a fresh new Flutter project with Flutter create and added just firebase_core package. Fixes in previous issue tried and failed.

import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {

  // Firebase checking configured default app and its options
  // options read from google services files
  // - Android from /android/app/google-services.json
  // - iOS form /ios/Runner/GoogleService-Info.plist
  Future<void> _allApps() async {

    // List of all apps as FirebaseApp objects, but default is only one
    // FirebaseApp.allApps() - Returns a list of all extant FirebaseApp instances, or null if there are none
    final List<FirebaseApp> apps = await FirebaseApp.allApps();
    if(apps != null) {
      String appName = apps[0].name;
      print('Currently configured app is : $appName');

      // Select the first app, probably only one
      // FirebaseApp.appNamed - Returns a previously created FirebaseApp instance with the given name, or null if there is none
      final FirebaseApp app = await FirebaseApp.appNamed(appName);

      // FirebaseApp object .options - Getter returns a copy of the options for this app
      // Do Not wan this in most apps
      final FirebaseOptions options = await app?.options;
      print('Current options for app: $appName , with options: $options');

    } else {
      print('ERROR: Problem getting Firebase app name and options !!!');
    }

  }

  @override
  Widget build(BuildContext context) {

    _allApps();

    return MaterialApp(
      title: 'Flutter Firebase Demo',
      theme: ThemeData(
        primarySwatch: Colors.orange,
      ),
      home: MyHomePage(title: 'Flutter Firebase Demo'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.display1,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}

Flutter doctor.

flutter doctor -v
[✓] Flutter (Channel stable, v1.9.1+hotfix.6, on Mac OS X 10.14.6 18G103, locale en-AU)
• Flutter version 1.9.1+hotfix.6 at /Users/gamma/Documents/flutter
• Framework revision 68587a0 (6 weeks ago), 2019-09-13 19:46:58 -0700
• Engine revision b863200c37
• Dart version 2.5.0

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/gamma/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• ANDROID_HOME = /Users/gamma/Library/Android/sdk
• Java binary at: /Applications/Android Studio 3.5 Preview.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.1, Build version 11A1027
• CocoaPods version 1.7.5

[✓] Android Studio (version 3.5)
• Android Studio at /Applications/Android Studio 3.5 Preview.app/Contents
• Flutter plugin version 40.2.2
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] VS Code (version 1.39.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.5.1

[✓] Connected device (2 available)
• Nexus 6P • CVH7N15A17000241 • android-arm64 • Android 8.1.0 (API 27)
• Mike's iPhone • 5604a58ae42681b47ea35479c1e06e2a43aac97d • ios • iOS 12.4.2

• No issues found!
@sunjianan9900
Copy link

same issue , only work on android
xcode11.1
flutter 1.9.1
firebase_core 0.4.0+9

@workerbee22
Copy link
Author

Note that other Firebase services packages seem to work on iOS, but only because they seem to detect no instance of a Firebase app object created by firebase_core and then create a new instance. So this bug is only evident if you have a project with ONLY firebase_core by itself.

@sunjianan9900
Copy link

@sunjianan9900 exactly which ios file did you delete? Then you appear to have repaired the project with flutter create .... Are you sure this fixed it? Please do a flutter clean to make sure.

If I create a brand new flutter project with swift support and add code at top of this issue. You will find it fails still.

yes I just delete the hole ios file in project
then 'flutter create -i swift .' and open xcode to reset all thing
and run it
and then I pass the firebase test

@sunjianan9900
Copy link

I do flutter clean and flutter run on anoter iphone
it still work
I got 2 iphone user info on analytics now

@sunjianan9900
Copy link

I delete my ios file
and run
flutter create -i swift .
Then it finally fixed......

@workerbee22
Copy link
Author

@sunjianan9900 Note that the issue is using firebase_core which does not return an app instance. Yes it will work if you then also use firebase_analytics, but only because if analytics does not find an app instance or the default, it re-creates one ... and thus it then works. So this is a workaround for the time being that does work.

But you will probably find your return from firebase_core is still always null (see original issue code posted). Which is the actual problem.

@workerbee22
Copy link
Author

@sunjianan9900 exactly which ios file did you delete? Then you appear to have repaired the project with flutter create .... Are you sure this fixed it? Please do a flutter clean to make sure.

If I create a brand new flutter project with swift support and add code at top of this issue. You will find it fails still.

@Ehesp Ehesp added impact: customer A bug with low impact (e.g. affecting only a few customers or has a workaround). (P3) plugin: core labels Apr 21, 2020
@Salakar
Copy link
Member

Salakar commented Jul 3, 2020

Hey, our firebase_core rework has now landed on master via #2890 - we hope to start publishing preview releases to test out next week which should solve this issue (and others).

Thank you for raising this issue 👍

@Salakar Salakar closed this as completed Jul 3, 2020
@firebase firebase locked and limited conversation to collaborators Aug 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
impact: customer A bug with low impact (e.g. affecting only a few customers or has a workaround). (P3) plugin: core type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants