transistorsoft / react-native-background-geolocation

Sophisticated, battery-conscious background-geolocation with motion-detection
http://shop.transistorsoft.com/pages/react-native-background-geolocation
MIT License
2.65k stars 426 forks source link

Crash when app started with changed (insufficient) permissions #635

Closed mschipperheyn closed 5 years ago

mschipperheyn commented 5 years ago

Our app uses background geolocation processing. When the app is in the foreground and location permissions are changed, the onProviderChange handler executed and directs our users to our location permission page.

However, when the user changes permissions while the app is not active and then opens the app a crash immediately happens. I can't say with 100% certainty that this is caused by geolocation, but since it's the only background processing going on and the app doesn't even start, I assume this is the case.

Your Environment

reset: true,
foregroundService: true,
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_NAVIGATION,
distanceFilter: 0,
locationUpdateInterval: 20000,
locationAuthorizationRequest: 'Always',
locationAuthorizationAlert: {
titleWhenOff: 'You need to enable location tracking',
titleWhenNotEnabled: 'You need to enable background location tracking',
instructions: "You must enable 'Always' in location-services",
},
stopTimeout: 1,
debug: __DEV__ && Config.GEOLOCATION_DEBUG === 'true',
logLevel:
__DEV__ && Config.GEOLOCATION_DEBUG === 'true' ?
    BackgroundGeolocation.LOG_LEVEL_VERBOSE :
    BackgroundGeolocation.OFF,
stopOnTerminate: false,
startOnBoot: true,
allowIdenticalLocations: true,
batchSync: false,
autoSync: true,
url: graphqlEndpoint,
httpRootProperty: '.',
locationTemplate: locationTemplate(driverId, vehicleId),
method: 'POST',
headers: {
    authorization: `Bearer ${token}`,
},

Expected Behavior

Location permission detection should call the location provider change handler

Actual Behavior

Hard crash

Steps to Reproduce

Implement geolocation with background processing. Close app Turn location permissions to : When in use Restart application

Context

Testing what happens if location permissions change while the app is off

Debug logs

 ************************ Crash Handler Notice ************************
    *     App is running in a debugger. Masking out unsafe monitors.     *
    * This means that most crashes WILL NOT BE RECORDED while debugging! *
    **********************************************************************
INFO : KSCrash.m (345): -[KSCrash sendAllReportsWithCompletion:]: Sending 0 crash reports
2018-12-17 13:05:55.848 [info][tid:main][RCTCxxBridge.mm:216] Initializing <RCTCxxBridge: 0x600003bb8870> (parent: <RCTBridge: 0x600002faafb0>, executor: (null))
2018-12-17 13:05:55.964 [info][tid:main][RCTRootView.m:293] Running application swoop ({
    initialProps =     {
    };
    rootTag = 1;
})
ℹ️-[TSLocationManager init] {
    activityRecognitionInterval = 10000;
    activityType = 1;
    autoSync = 1;
    autoSyncThreshold = 0;
    batchSync = 0;
    debug = 1;
    desiredAccuracy = "-2";
    desiredOdometerAccuracy = 100;
    disableElasticity = 0;
    disableLocationAuthorizationAlert = 0;
    disableMotionActivityUpdates = 0;
    disableStopDetection = 0;
    distanceFilter = 0;
    elasticityMultiplier = 1;
    enabled = 1;
    extras =     {
    };
    geofenceInitialTriggerEntry = 1;
    geofenceProximityRadius = 1000;
    geofenceTemplate = "";
    headers =     {
        authorization = "Bearer TOKEN";
    };
    heartbeatInterval = 60;
    httpRootProperty = ".";
    httpTimeout = 60000;
    isFirstBoot = 0;
    isMoving = 0;
    lastLocationAuthorizationStatus = 4;
    locationAuthorizationAlert =     {
        instructions = "You must enable 'Always' in location-services";
        titleWhenNotEnabled = "You need to enable background location tracking";
        titleWhenOff = "You need to enable location tracking";
    };
    locationAuthorizationRequest = Always;
    locationTemplate = "{ \"id\": \"UpdatePartnerVehicleMutation\", \"query\": \"mutation UpdatePartnerVehicleMutation( $input: UpdatePartnerVehicleInput! ) { updatePartnerVehicle(input: $input) { partnerVehicle { id driver { id } lat lng } } } \", \"variables\": { \"input\": { \"partnerVehicle\": { \"id\": \"2ltXaYHfw7XOFbpkK01Jbx\", \"lat\": <%= latitude %>, \"lng\": <%= longitude %>, \"driver\": { \"id\": \"7655NwP22QAQ1yXKg48vGB\" } } } } }";
    locationTimeout = 60;
    locationsOrderDirection = ASC;
    logLevel = 5;
    logMaxDays = 3;
    maxBatchSize = "-1";
    maxDaysToPersist = 1;
    maxRecordsToPersist = "-1";
    method = POST;
    minimumActivityRecognitionConfidence = 70;
    odometer = 0;
    params =     {
    };
    pausesLocationUpdatesAutomatically = 0;
    preventSuspend = 0;
    schedule =     (
    );
    schedulerEnabled = 0;
    startOnBoot = 1;
    stationaryRadius = 25;
    stopAfterElapsedMinutes = "-1";
    stopDetectionDelay = 0;
    stopOnStationary = 0;
    stopOnTerminate = 0;
    stopTimeout = 1;
    trackingMode = 1;
    url = "https://www.ourdomain.com/graphql";
    useSignificantChangesOnly = 0;
}
✅-[LocationDAO unlock]_block_invoke UNLOCKED ALL RECORDS
ℹ️-[GeofenceDAO init] CREATE TABLE IF NOT EXISTS geofences (id INTEGER PRIMARY KEY AUTOINCREMENT, identifier TEXT NOT NULL UNIQUE, latitude DOUBLE NOT NULL, sin_latitude DOUBLE NOT NULL, cos_latitude DOUBLE NOT NULL, longitude DOUBLE NOT NULL, sin_longitude DOUBLE NOT NULL, cos_longitude DOUBLE NOT NULL, radius DOUBLE NOT NULL, notifyOnEntry BOOLEAN NOT NULL DEFAULT 0, notifyOnExit BOOLEAN NOT NULL DEFAULT 0, notifyOnDwell BOOLEAN NOT NULL DEFAULT 0, loiteringDelay DOUBLE NOT NULL DEFAULT 0, extras TEXT)
ℹ️-[GeofenceDAO init] CREATE index IF NOT EXISTS identifier ON geofences (identifier);CREATE index IF NOT EXISTS latitude ON geofences (latitude);CREATE index IF NOT EXISTS longitude ON geofences (longitude);CREATE index IF NOT EXISTS sin_latitude ON geofences (sin_latitude);CREATE index IF NOT EXISTS cos_latitude ON geofences (cos_latitude);CREATE index IF NOT EXISTS sin_longitude ON geofences (sin_longitude);CREATE index IF NOT EXISTS cos_longitude ON geofences (cos_longitude);
2018-12-17 13:05:55.992 [info][tid:main][RCTCxxBridge.mm:930] Invalidating <RCTCxxBridge: 0x600003bb8870> (parent: <RCTBridge: 0x600002faafb0>, executor: RCTWebSocketExecutor)
2018-12-17 13:05:55.992 [info][tid:main][RCTCxxBridge.mm:216] Initializing <RCTCxxBridge: 0x600003bb8d20> (parent: <RCTBridge: 0x600002faafb0>, executor: RCTWebSocketExecutor)
ℹ️-[TSLocationManager removeListeners] 
🔵-[TSLocationManager locationManager:didChangeAuthorizationStatus:] status 4
🔴-[LocationManager stopWatchPosition] STOP
ℹ️-[TSLocationManager removeListeners] 
ℹ️+[LocationAuthorization run:] status: 4
libc++abi.dylib: terminating with uncaught exception of type NSException
christocracy commented 5 years ago

I see no stacktrace pointing to the TSLocationManager.

mschipperheyn commented 5 years ago

Sorry

Process:               swoop [34625]
Path:                  /Users/USER/Library/Developer/CoreSimulator/Devices/80B97AB7-4617-442A-B7E8-BD01FD26AA68/data/Containers/Bundle/Application/F471A1E1-A493-43CE-A2EC-4F77805DA622/swoop.app/swoop
Identifier:            swoop
Version:               1.0.0 (1)
Code Type:             X86-64 (Native)
Parent Process:        launchd_sim [28591]
Responsible:           swoop [34625]
User ID:               501

Date/Time:             2018-12-17 12:58:23.841 -0200
OS Version:            Mac OS X 10.14.1 (18B75)
Report Version:        12
Bridge OS Version:     3.1 (16P1065)
Anonymous UUID:        CE724EC2-2DDF-2D15-AAC5-D1337BD5BEE6

Sleep/Wake UUID:       08B5F241-8D08-4BBC-BD7E-765855A92947

Time Awake Since Boot: 72000 seconds
Time Since Wake:       7200 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Application Specific Information:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Actions added to UIAlertController must have a title'
terminating with uncaught exception of type NSException
abort() called
CoreSimulator 581.2 - Device: iPhone 8 - Runtime: iOS 12.1 (16B91) - DeviceType: iPhone 8

Application Specific Backtrace 1:
0   CoreFoundation                      0x00000001120451bb __exceptionPreprocess + 331
1   libobjc.A.dylib                     0x00000001101d6735 objc_exception_throw + 48
2   CoreFoundation                      0x0000000112044f42 +[NSException raise:format:arguments:] + 98
3   Foundation                          0x000000010fbd9877 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 194
4   UIKitCore                           0x000000011e007147 +[UIAlertAction _actionWithTitle:descriptiveText:image:style:handler:shouldDismissHandler:] + 660
5   UIKitCore                           0x000000011e0071e5 +[UIAlertAction _actionWithTitle:image:style:handler:shouldDismissHandler:] + 138
6   UIKitCore                           0x000000011e007389 +[UIAlertAction actionWithTitle:style:handler:] + 98
7   swoop                               0x000000010e4ffc78 +[LocationAuthorization getAlertController] + 366
8   swoop                               0x000000010e4ff513 +[LocationAuthorization run:] + 561
christocracy commented 5 years ago

You have provided only 3 of 5 keys. You must provide all the keys. See the docs

⚠️ Warning: If you choose to configure locationAuthorizationAlert, you must provide ALL the keys of LocationAuthorizationAlert keys — not just some.

locationAuthorizationAlert =     {
        instructions = "You must enable 'Always' in location-services";
        titleWhenNotEnabled = "You need to enable background location tracking";
        titleWhenOff = "You need to enable location tracking";
    };