0

I am writing a switch case that will return a user friendly message to the user informing them what location permissions have been given to my IOS application (which completely relies on the location). So far I have created the following switch case. It does not quite work properly as I would like it to identify which setting the user has selected and respond with the correct message. Currently it will only detect whether the user has selected 'Always' or 'Never' and not be able to identify the other 2 options. The options that I ould like it to identify are - Allow Location Access - 'Never', 'Ask Next Time', 'Whilst Using the App' and 'Always'.

    private void CheckPermissions(bool enabled)
            {
                 MainThread.BeginInvokeOnMainThread(() =>
                 {
                  PermissionStatus alwaysAllowLocationPermission = default;
                  if (alwaysAllowLocationPermission)

                    switch (enabled)
                    case alwaysAllowLocationPermission = PermissionStatus.Granted:
                    {
                      var okAlertController = UIAlertController.Create("Permissions good", $"You have not given permission to 'always' use location.", UIAlertControllerStyle.Alert);
                    okAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
                    PresentViewController(okAlertController, true, null);
                }
                break;
                case alwaysAllowLocationPermission = PermissionStatus.Denied:
                {
                    var okAlertController = UIAlertController.Create("Permission denied", $"You have not given permission to 'always' use location.", UIAlertControllerStyle.Alert);
                    okAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
                    PresentViewController(okAlertController, true, null);
                }
                break;
                case alwaysAllowLocationPermission = PermissionStatus.Restricted:
                {
                    var okAlertController = UIAlertController.Create("Permission restricted", $"You have not given permission to 'always' use location.", UIAlertControllerStyle.Alert);
                    okAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
                    PresentViewController(okAlertController, true, null);
                }
                break;
            default:
                break;
            }
        }
        }  else
        {

            var okAlertController = UIAlertController.Create("Missing Permissions”, $"You have not given permission to 'always' use location.", UIAlertControllerStyle.Alert);
            okAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
            PresentViewController(okAlertController, true, null);
        }
    };
};
Kalvin
  • 13
  • 3
  • The cases are [here](https://developer.apple.com/documentation/corelocation/clauthorizationstatus) `Restricted` means that your app can't use location, so don't even ask. `denied` means you have asked and it was denied (or the user has gone into settings and denied permission). Always and when in use are obvious. Never asked and ask next time show up as "not determined". There is also an [accuracy permission](https://developer.apple.com/documentation/corelocation/cllocationmanager/3600215-accuracyauthorization) on iOS 14+ – Paulw11 Jul 01 '21 at 09:27
  • Would it run through the same Swich case if the user is signing in to the app for the 1st timeor if the user is returning to the app afetr using another application? – Kalvin Jul 01 '21 at 11:50
  • Also in C# there is another property called .disabled which is what I thought .restricted was. Do you know the difference? I think syntacticallyI have got something wrong with the above code as well as it currently won't run – Kalvin Jul 01 '21 at 12:01

0 Answers0