capacitor-community / background-geolocation

A Capacitor plugin that sends you geolocation updates, even while the app is in the background.
MIT License
185 stars 57 forks source link

Doesn't work on iOS 14 with Angular 11 #6

Closed pdrhlik closed 3 years ago

pdrhlik commented 3 years ago

Describe the bug I upgraded my Ionic Angular project to Angular 11 and running on my iOS device stopped wotking.

To Reproduce Steps to reproduce the behavior:

  1. Run ionic capacitor run ios -l --watch --external
  2. Click Build and run on device in XCode
  3. App crashes before being loaded

Ionic info

Ionic:

   Ionic CLI                     : 6.12.4 (/usr/local/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.5.4
   @angular-devkit/build-angular : 0.1101.4
   @angular-devkit/schematics    : 11.1.4
   @angular/cli                  : 11.1.4
   @ionic/angular-toolkit        : 3.0.0

Capacitor:

   Capacitor CLI   : 2.4.0
   @capacitor/core : 2.4.0

Utility:

   cordova-res (update available: 0.15.3) : 0.15.2
   native-run (update available: 1.3.0)   : 1.2.2

System:

   NodeJS : v12.18.3 (/usr/local/Cellar/node@12/12.18.3/bin/node)
   npm    : 6.14.6
   OS     : macOS Catalina

Additional info I tried cleaning all XCode caches, removing and recreating www and node_modules folders and nothing helped. It works on Android, the only issue is with iOS.

XCode says that the build succeeded but then it crashes on line 5 in a file AppDelegate.swift. The error message there is Thread 1: "Invalid parameter not satisfying: !stayUp || CLClientIsBackgroundable(internal->fClient) || _CFMZEnabled()".

The XCode error stack is following:

⚡️  To Native ->  BackgroundGeolocation addWatcher 74957257
2021-02-07 22:29:20.797206+0100 App[561:73313] *** Assertion failure in -[CLLocationManager setAllowsBackgroundLocationUpdates:], CLLocationManager.m:927
2021-02-07 22:29:20.797561+0100 App[561:73313] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: !stayUp || CLClientIsBackgroundable(internal->fClient) || _CFMZEnabled()'
*** First throw call stack:
(0x194d89114 0x1a8625cb4 0x194c98308 0x195f802c8 0x19a8941c4 0x101021e4c 0x1010221e0 0x10108bdb8 0x10108d5fc 0x10109ba6c 0x194d08c30 0x194d030e8 0x194d02200 0x1aae7f598 0x1975cbbcc 0x1975d11a0 0x100ddb6ec 0x1949e1588)
libc++abi.dylib: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: !stayUp || CLClientIsBackgroundable(internal->fClient) || _CFMZEnabled()'
terminating with uncaught exception of type NSException
(lldb) 

Let me know if you need any more info or see any obivous mistakes on my side.

Thanks, Patrik

diachedelic commented 3 years ago

Are you missing some plist configuration for the iOS project? See https://stackoverflow.com/questions/32000531/nsinternalinconsistencyexception-invalid-parameter-not-satisfying-stayup

pdrhlik commented 3 years ago

Thanks, @diachedelic. It wasn't the accepted answer. I had everything correctly specified in Info.plist. The issue was that I didn't check a background mode location update capability in Xcode. I did so as per thing answer https://stackoverflow.com/questions/32000531/nsinternalinconsistencyexception-invalid-parameter-not-satisfying-stayup#answer-51430411 and it works now.

Maybe this should be mentioned in the iOS section of the README?

diachedelic commented 3 years ago

Thanks, I have added it to the README in v0.3.9.