transistorsoft / flutter_background_geolocation_firebase

Firebase proxy for Flutter Background Geolocation SDK
MIT License
21 stars 7 forks source link

Crash on start recording on iOS #4

Closed fne00 closed 5 years ago

fne00 commented 5 years ago

Hi Chris, I have an App using flutter_background_geolocation. I tried adding flutter_background_geolocation_firebase and it seems to be working fine for Android, but not for iOS. Your Environment

[✓] Flutter (Channel stable, v1.5.4-hotfix.2, on Mac OS X 10.14.5 18F132, locale en-AU)
    • Flutter version 1.5.4-hotfix.2 at /Users/peffeney/flutter
    • Framework revision 7a4c33425d (6 weeks ago), 2019-04-29 11:05:24 -0700
    • Engine revision 52c7a1e849
    • Dart version 2.3.0 (build 2.3.0-dev.0.5 a1668566e5)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /Users/peffeney/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 10.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.2.1, Build version 10E1001
    • ios-deploy 1.9.4
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.4)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 36.0.1
    • Dart plugin version 183.6270
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)

[✓] IntelliJ IDEA Ultimate Edition (version 2019.1.1)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 34.0.4
    • Dart plugin version 191.7019

[✓] Connected device (2 available)
    • Android SDK built for x86 • emulator-5554                        • android-x86 • Android 8.1.0 (API 27) (emulator)
    • iPhone Xʀ                 • 44E00CBE-E1D8-4F83-8618-B64DFF4B5B02 • ios         • com.apple.CoreSimulator.SimRuntime.iOS-12-2 (simulator)

• No issues found!

*To Reproduce** Steps to reproduce the behavior:

  flutter_background_geolocation: ^1.0.7
  background_geolocation_firebase:
    git:
      url: https://github.com/transistorsoft/flutter_background_geolocation_firebase
      // 1.  First configure the Firebase Adapter.
      BackgroundGeolocationFirebase.configure(BackgroundGeolocationFirebaseConfig(
          locationsCollection: "locations",
          geofencesCollection: "geofences",
          updateSingleDocument: false
      ));

      bg.BackgroundGeolocation.onLocation(_onLocation, _onLocationError);
    // 2.  Configure the plugin
    bg.BackgroundGeolocation.ready(bg.Config(
            desiredAccuracy: bg.Config.DESIRED_ACCURACY_NAVIGATION,
            distanceFilter: 0.0,
            // no min distance
            locationUpdateInterval: 0,
            // no min time
            fastestLocationUpdateInterval: 200,
            // 200mS max rate of new data points - 0 is not recommended
            useSignificantChangesOnly: false,
            stopOnTerminate: true,
            // will stop recording when crash/terminate
            startOnBoot: false,
            foregroundService: true,
            // Android only - defaults to true for >Android 8.0 - mandatory
            enableHeadless: true,
            // Ignored because I have stopOnTerminate
            stopTimeout: 10,
            // 10 mins - if stationary for >10mins stops until movement is detected again
            debug: false,
            autoSync: false,
            // auto upload of track for live tracking
            url: 'http://13.211.10.150:9000/locations/$username',
            params: deviceParams,
            logLevel: bg.Config.LOG_LEVEL_VERBOSE))
        .then((bg.State state) {
      setState(() {
        _enabled = state.enabled;
        _isMoving = state.isMoving;
      });
      //     _createNewTrack(); // FNE Database creates a new track
    }).catchError((error) {
      print('[ready] ERROR: $error');
    });

Debug logs

The flutter_background_geolocation_firebase sample App worked for both Android and iOS.

When I integrated flutter_background_geolocation_firebase into my App, it works fine for Android - Seems to be posting locations to my Firebase database.

In iOS - crashes with:

2019-06-09 10:20:10.520925+1000 Runner[21851:12979374]  - <AppMeasurement>[I-ACS036002] Analytics screen reporting is enabled. Call +[FIRAnalytics setScreenName:setScreenClass:] to set the screen name or override the default screen class name. To disable screen reporting, set the flag FirebaseScreenReportingEnabled to NO (boolean) in the Info.plist
2019-06-09 10:20:10.875711+1000 Runner[21851:12979459] flutter: Observatory listening on http://127.0.0.1:55575/_VQ0B1j2Lcc=/
2019-06-09 10:22:07.709504+1000 Runner[21851:12979283] ******************* confiugure: {
    geofencesCollection = geofences;
    locationsCollection = locations;
    updateSingleDocument = 0;
}
2019-06-09 10:22:07.709724+1000 Runner[21851:12979283] ************** isRegistered: 0
2019-06-09 10:22:07.711195+1000 Runner[21851:12980418] 5.15.0 - [Firebase/Core][I-COR000003] The default Firebase app has not yet been configured. Add `[FIRApp configure];` (`FirebaseApp.configure()` in Swift) to your application initialization. Read more: https://goo.gl/ctyzm8.
2019-06-09 10:22:07.755412+1000 Runner[21851:12979283] *** Terminating app due to uncaught exception 'FIRAppNotConfiguredException', reason: 'Failed to get FirebaseApp instance. Please call FirebaseApp.configure() before using Firestore'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000111b916fb __exceptionPreprocess + 331
    1   libobjc.A.dylib                     0x0000000110a4bac5 objc_exception_throw + 48
    2   Runner                              0x000000010c21b519 +[FIRFirestore firestore] + 137
    3   Runner                              0x000000010c509dcd -[BackgroundGeolocationFirebasePlugin configure:result:] + 605
    4   Runner                              0x000000010c509b15 -[BackgroundGeolocationFirebasePlugin handleMethodCall:result:] + 261
    5   Flutter                             0x000000010d6d8b9a __45-[FlutterMethodChannel setMethodCallHandler:]_block_invoke + 115
    6   Flutter                             0x000000010d6f6c52 _ZNK7flutter21PlatformMessageRouter21HandlePlatformMessageEN3fml6RefPtrINS_15PlatformMessageEEE + 166
    7   Flutter                             0x000000010d6fa1ee _ZN7flutter15PlatformViewIOS21HandlePlatformMessageEN3fml6RefPtrINS_15PlatformMessageEEE + 38
    8   Flutter                             0x000000010d74eebb _ZNSt3__110__function6__funcIZN7flutter5Shell29OnEngineHandlePlatformMessageEN3fml6RefPtrINS2_15PlatformMessageEEEE4$_27NS_9allocatorIS8_EEFvvEEclEv + 57
    9   Flutter                             0x000000010d7069ff _ZN3fml15MessageLoopImpl10FlushTasksENS0_9FlushTypeE + 487
    10  Flutter                             0x000000010d70a074 _ZN3fml17MessageLoopDarwin11OnTimerFireEP16__CFRunLoopTimerPS0_ + 26
    11  CoreFoundation                      0x0000000111af93e4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
    12  CoreFoundation                      0x0000000111af8ff2 __CFRunLoopDoTimer + 1026
    13  CoreFoundation                      0x0000000111af885a __CFRunLoopDoTimers + 266
    14  CoreFoundation                      0x0000000111af2efc __CFRunLoopRun + 2220
    15  CoreFoundation                      0x0000000111af2302 CFRunLoopRunSpecific + 626
    16  GraphicsServices                    0x000000011a0dc2fe GSEventRunModal + 65
    17  UIKitCore                           0x00000001164caba2 UIApplicationMain + 140
    18  Runner                              0x000000010c192200 main + 112
    19  libdyld.dylib                       0x00000001125ae541 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Additional context Maybe I've missed something with the iOS setup? Any assistance would be appreciated thanks, Peter

christocracy commented 5 years ago

See the iOS setup instructions:

The default Firebase app has not yet been configured. Add [FIRApp configure]; (FirebaseApp.configure() in Swift) to your application initialization. Read more:

fne00 commented 5 years ago

Chris, Sorry about that ... followed generic Firebase instructions not your specific ones.. I've made those changes, but now get a crash on startup:

Launching lib/main.dart on iPhone Xʀ in debug mode...
Running Xcode build...
Xcode build done.                                            9.4s
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000114e266fb __exceptionPreprocess + 331
    1   libobjc.A.dylib                     0x0000000113ce0ac5 objc_exception_throw + 48
    2   CoreFoundation                      0x0000000114e26555 +[NSException raise:format:] + 197
    3   Runner                              0x000000010f68d6f2 +[FIRApp configure] + 562
    4   Runner                              0x000000010f68b1f8 -[AppDelegate application:didFinishLaunchingWithOptions:] + 120
    5   UIKitCore                           0x000000011975f311 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 280
    6   UIKitCore                           0x0000000119760cad -[UIApplication _callInitializationDe<…>
Error connecting to the service protocol: HttpException: , uri = http://127.0.0.1:61596/CZjHRRNwfEA=/ws

Regards Peter

christocracy commented 5 years ago

This is not caused by the plugins: google it:

Error connecting to the service protocol: HttpException: , uri = http://127.0.0.1:61596/CZjHRRNwfEA=/ws

fne00 commented 5 years ago

OK thanks - Still trying to get to the bottom of it. It is curious that if I comment out [FIRApp configure]; It starts OK.

fne00 commented 5 years ago

Fixed. So, just to record the fix, in case someone else has this issue....

Remedy:

Regards Peter