Skip to content
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

IOS: Does not ask for location permission. #50

Closed
wemersonrv opened this issue Apr 27, 2020 · 10 comments
Closed

IOS: Does not ask for location permission. #50

wemersonrv opened this issue Apr 27, 2020 · 10 comments

Comments

@wemersonrv
Copy link

Hello.

It's working fine on Android. But on iOS it not asks for permission and of course, not works.

See app permission... not have location permissions:

image

Do i miss something???

Below my files as oriented in documentation:

AppDelegate.swift

import UIKit
import Flutter
import Firebase
import background_locator
import GoogleMaps

func registerPlugins(registry: FlutterPluginRegistry) -> () {
    GeneratedPluginRegistrant.register(with: registry)
}

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    FirebaseApp.configure()
    GeneratedPluginRegistrant.register(with: self)
    // Background Location BEGIN
    BackgroundLocatorPlugin.setPluginRegistrantCallback(registerPlugins)
    // Background Location END

    // Google MAPS BEGIN
    GMSServices.provideAPIKey("-----------------------")
    // Google MAPS END
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

Info.plist

		<!-- Background Location Settings BEGIN -->
		<key>
			NSLocationAlwaysAndWhenInUseUsageDescription
		</key>
		<string>
			Location Needed
		</string>
		<key>
			NSLocationAlwaysUsageDescription
		</key>
		<string>
			Location Needed
		</string>
		<key>
			NSLocationWhenInUseUsageDescription
		</key>
		<string>
			Location Needed
		</string>
		<key>
			UIBackgroundModes
		</key>
		<array>
			<string>
				location
			</string>
		</array>
		<!-- Background Location Settings BEGIN -->

Runner settings
WhatsApp Image 2020-04-27 at 08 31 00

@gpibarra
Copy link
Contributor

The library does not ask for permissions. Permissions should be asked in the main app(for example package location_permissions/location_permissions.
You did this?
https://github.com/rekab-app/background_locator/blob/86ef3a83714f9f2dc0e19f4fa711e39d6e2789f3/example/lib/main.dart#L174

@wemersonrv
Copy link
Author

The library does not ask for permissions. Permissions should be asked in the main app(for example package location_permissions/location_permissions.
You did this?
https://github.com/rekab-app/background_locator/blob/86ef3a83714f9f2dc0e19f4fa711e39d6e2789f3/example/lib/main.dart#L174

Yes i do. see my code:

@override
  Widget build(BuildContext context) {
    if (!isRunning && isBackgroundActive) {
      _checkLocationPermission();
    }

    return OKToast(
      duration: Duration(seconds: Helpers.toastDuration),
      position: ToastPosition.bottom,
      handleTouth: true,
      dismissOtherOnShow: true,
      child: Visibility(
        visible: (linkFetch == true),

        ...


  void _checkLocationPermission() async {
    final access = await LocationPermissions().checkPermissionStatus();
    switch (access) {
      case PermissionStatus.unknown:
      case PermissionStatus.denied:
      case PermissionStatus.restricted:
        final permission = await LocationPermissions().requestPermissions(
          permissionLevel: LocationPermissionLevel.locationAlways,
        );
        if (permission == PermissionStatus.granted) {
          _startLocator();
        } else {
          // show error
        }
        break;
      case PermissionStatus.granted:
        _startLocator();
        break;
    }
  }

  void _startLocator() {
    BackgroundLocator.registerLocationUpdate(
      LocationBackground.callback,
      androidNotificationCallback: LocationBackground.notificationCallback,
      settings: LocationSettings(
        notificationTitle: "My App",
        notificationMsg: "My App Title",
        notificationIcon: 'ic_background',
        wakeLockTime: 20,
        autoStop: false,
        interval: 60 * 5, // 5 minutes (300 secs)
      ),
    );
    setState(() {
      isRunning = true;
    });
  }

It works on android, and ask for permission... see:
image

But in iOS do not ask for permission, and the location permission is missing in permission list in app detail. See here:

image

@mehdok
Copy link
Collaborator

mehdok commented May 6, 2020

Did you followed the instruction for setting up on iOS ?

You have to add location permission in Info.plist

@wemersonrv
Copy link
Author

Did you followed the instruction for setting up on iOS ?

You have to add location permission in Info.plist

Yes i do!

When i opened this post i add the Info.plist portion that has backgrond location settings... I thing i do not miss any setting...

@gpibarra
Copy link
Contributor

gpibarra commented May 6, 2020

Did you try running exactly the "example" from this repository? The Info.plist configuration looks good, but maybe there is something that the configuration is different.
If you try the "example" and it requires the permissions, we discard that it is not a problem of the library, but some missing documentation for the correct configuration.

@wemersonrv
Copy link
Author

Works the example and works... weird... will investigate if something is missing here on my project.

But, in the repo "example" project is causing the same problem of this issue #55 (comment)_

@gpibarra
Copy link
Contributor

try with the previous version of the repo, maybe there is something in the configuration that is missing (in that case better the documentation). Then we go back to the latest version of the library and wait to solve the bug

@ghost
Copy link

ghost commented Jun 1, 2020

I have the same issue

@ghost
Copy link

ghost commented Jun 4, 2020

Aaaaah! It is the App Target!

NSLocationAlwaysUsageDescription is for IOS 10+ I had IOS 8 set and removing this fixed the issue. But then also changing my target fixed it also.

@mehdok
Copy link
Collaborator

mehdok commented Aug 17, 2020

I think this problem is fixed, so I'm closing this issue, but feel free to open it anytime;

@mehdok mehdok closed this as completed Aug 17, 2020
jocelyngriselle pushed a commit to sncf-connect-tech/background_locator that referenced this issue Apr 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants