Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Xamarin Forms location services work on iOSimulator but not on Testflight build

$
0
0

Repost from stackoverflow, if its ok...

I am working on a Xamarin Forms app that asks the user for Location services permission using PermissionsPlugin by James Montemagno. I use Visual Studio 2017 in Windows and a Virtual Machine as my MAC build host (macOS High Sierra 10.13.4).

My problem is that the app works as intended when deployed to the iOSimulator. It prompts the user to allow or deny the use of location services. In the simulator, the app is even listed under Settings>Privacy>Location Services. But after delivering the built IPA file to Apple and testing it via Testflight, the app does not prompt anything and just loads indefinitely. The app is also not listed in Settings>Privacy>Location Services.

Here is the code from the app for requesting permission:

async Task<bool> AskPermission()
{
    var hasPermission = false;

    try
    {
        var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location);

        if (status != PermissionStatus.Granted)
        {

            if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Location))
            {
                await App.Current.MainPage.DisplayAlert("Need location", "Allow app to access location?", "OK", "Cancel");
            }

            var results = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Location);

            if (results.ContainsKey(Permission.Location))
            {
                status = results[Permission.Location];
            }
        }

        if (status == PermissionStatus.Granted)
        {
            hasPermission = true;
        }
        else if (status != PermissionStatus.Unknown)
        {
            await App.Current.MainPage.DisplayAlert("Location Denied", "Can not continue, try again.", "OK");
        }
    }
    catch (Exception ex)
    {

    }

    return hasPermission;
}

This is one of the methods that is called on click of a button. An activity indicator then appears since it is bound to a boolean that is toggled when the all methods are started/done.

This is pretty much the sample code from James Montemagno's plugin. I suspect the app gets stucked on await CrossPermissions.Current.RequestPermissionsAsync(Permission.Location).

I also added the necessary additions to Info.plist in the iOS project of the App:

            <key>NSLocationWhenInUseUsageDescription</key>
            <string>prompt message</string>
            <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
            <string>prompt message</string>

I also tested variations where I used NSLocationAlwaysUsageDescription instead of NSLocationWhenInUseUsageDescription but got similar results...

I tested this in iOSimulator (iPhone 5, 6, 7, all in 11.3, all worked) and tested in Testflight using an iPhone 7 and an iPad, both in 11.3 as well; unfortunately, both cases didn't prompt permission request dialog.

For reference, this works as intended in Android both in debugging and testing from Play store.


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>