transistorsoft / flutter_background_geolocation

Sophisticated, battery-conscious background-geolocation & geofencing with motion-detection
https://www.transistorsoft.com/shop/products/flutter-background-geolocation
Other
646 stars 240 forks source link

Location authorization alert #8

Closed solid-vovabeloded closed 5 years ago

solid-vovabeloded commented 6 years ago

Your Environment

Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel beta, v0.8.2, on Mac OS X 10.13.4 17E199, locale en-UA) [✓] Android toolchain - develop for Android devices (Android SDK 28.0.3) [✓] iOS toolchain - develop for iOS devices (Xcode 9.4.1) [✗] Android Studio (not installed) [✓] IntelliJ IDEA Ultimate Edition (version 2018.2.4) [✓] Connected devices (1 available)

! Doctor found issues in 1 category.

Expected Behavior

The authorization alert message should fully update every time plugin configuration updated

Actual Behavior

titleWhenNotEnabled, titleWhenOff, instructions fields updated successfully, but cancelButton and settingsButton does not update until application restart

Steps to Reproduce

Modify example app:

  1. Add some changing value to locationAuthorizationAlert strings
  2. Initialize plugin
  3. Make locationAuthorizationAlert values change
  4. Reinitialize plugin
  5. Some values of this alert will not change

Context

We are trying to localize our app using intl_helpers plugin but this bug makes impassable to translate this message, because some values not changing

simulator screen shot - iphone x - 2018-10-12 at 16 48 34 simulator screen shot - iphone x - 2018-10-12 at 16 48 51

christocracy commented 6 years ago

Thanks, I see the problem in the else clause:

+(UIAlertController*) getAlertController
{
    TSConfig *config = [TSConfig sharedInstance];
    NSDictionary *strings = [config getLocationAuthorizationAlertStrings];
    CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
    NSString *title = (status == kCLAuthorizationStatusDenied) ? strings[@"titleWhenOff"] : strings[@"titleWhenNotEnabled"];

    if (!alertController) {
        alertController = [UIAlertController alertControllerWithTitle:title message:strings[@"instructions"] preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:strings[@"cancelButton"] style:UIAlertActionStyleDefault handler:^(UIAlertAction* action) {
            [self hide];
        }];
        [alertController addAction:cancelAction];
        UIAlertAction* settingsAction = [UIAlertAction actionWithTitle:strings[@"settingsButton"] style:UIAlertActionStyleDefault handler:^(UIAlertAction* action) {
            NSURL *settingsURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
            [[UIApplication sharedApplication] openURL:settingsURL];
        }];
        [alertController addAction:settingsAction];
    } else {
        // alertController instance already exists here.  
        // TODO Need to fetch references to the buttons here and update their text.
        [alertController setTitle:title];
        [alertController setMessage:strings[@"instructions"]];
    }
    return alertController;
}

Carry on with your testing. This will be fixed soon.

solid-vovabeloded commented 6 years ago

@christocracy any way this can be fixed today/tomorrow? we need to make sure that languages are ok before pushing to the App Store and this issue is one of few remaining.

illia-romanenko commented 6 years ago

any updates on this?

christocracy commented 6 years ago

In the meantime, you can always disableAuthorizationAlert and implement your own alert in the onProviderChange event.

solid-vovabeloded commented 6 years ago

I've tried this approach recently and it is not working correctly. onProviderChange event triggers only after changing settings, but not after plugin initialization and thus we cannot show alert directly after plugin initialization like default alert message.

christocracy commented 6 years ago

Listen to onProviderChange before #ready.

#ready causes a providerchange event to fire. If you're not listening to the event before #ready, you'll miss the event.

solid-vovabeloded commented 6 years ago

I've checked this one. And it doesn't work too. #ready does not make onProviderChange event to fire even if I add this listener before #ready method

christocracy commented 6 years ago

@vova-beloded Show me your code where you're executing #ready and #onProviderChange

solid-vovabeloded commented 6 years ago
bgGeolocation.BackgroundGeolocation.onProviderChange((providerChange) {
      print('on provider change');
    });
    Map deviceParams = await bgGeolocation.Config.deviceParams;

    print('ready');
    await bgGeolocation.BackgroundGeolocation.ready(bgGeolocation.Config(
        reset: true,
        disableLocationAuthorizationAlert: true,
        desiredAccuracy: bgGeolocation.Config.DESIRED_ACCURACY_HIGH,
        distanceFilter: 10.0,
        stopOnTerminate: false,
        stationaryRadius: 5.0,
        startOnBoot: true,
        isMoving: true,
        foregroundService: true,
        notificationTitle: "xxx",
        notificationText: "xxx",
        stopTimeout: 1,
        debug: true,
        autoSync: true,
        url: 'http://tracker.transistorsoft.com/locations/vova-beloded',
        params: deviceParams,
        logLevel: bgGeolocation.Config.LOG_LEVEL_OFF));
      print('ready done');
christocracy commented 6 years ago

I see you viewing /locations/username in the browser.

It’s just /username

christocracy commented 6 years ago

locationAuthorizationAlert Should be fixed in 0.1.7

christocracy commented 6 years ago

Confirmation please.

christocracy commented 5 years ago

@vova-beloded Confirmation please.

illia-romanenko commented 5 years ago

confirmed

TheAlphamerc commented 4 years ago

In the meantime, you can always disableAuthorizationAlert and implement your own alert in the onProviderChange event.

I was looking for a property to disable built-in authorization alert and see I found it.