Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Forms-如果位置授权状态已更改,则会收到通知_Ios_Xamarin_Xamarin.ios_Xamarin.forms_Cllocationmanager - Fatal编程技术网

Ios Forms-如果位置授权状态已更改,则会收到通知

Ios Forms-如果位置授权状态已更改,则会收到通知,ios,xamarin,xamarin.ios,xamarin.forms,cllocationmanager,Ios,Xamarin,Xamarin.ios,Xamarin.forms,Cllocationmanager,我尝试在iOS的Xamarin.Forms中实现一个解决方案,如果用户更改了该位置的授权状态,它会通知我(请参见下面的代码)。因为第一次启动应用程序时,授权被拒绝或未确定(我不知道具体情况)。 但它似乎不起作用,只有在“允许”或“拒绝”上的“用户”选项卡之前才会触发该事件 也许其他人对此有更好的想法或其他解决方案。我已把自己定位在这方面 我的课堂上有地图(视图或任何东西): 以及iOS特定代码: public class Location : ILocation { public

我尝试在iOS的
Xamarin.Forms
中实现一个解决方案,如果用户更改了该位置的授权状态,它会通知我(请参见下面的代码)。因为第一次启动应用程序时,授权被拒绝或未确定(我不知道具体情况)。 但它似乎不起作用,只有在“允许”或“拒绝”上的“用户”选项卡之前才会触发该事件

也许其他人对此有更好的想法或其他解决方案。我已把自己定位在这方面

我的课堂上有地图(视图或任何东西):

以及iOS特定代码:

public class Location : ILocation    
{
    public Location()
    {
        var manager = new CLLocationManager();

        if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            manager.RequestWhenInUseAuthorization();

        manager.AuthorizationChanged += (sender, args) => {
            // Trigger event.
            OnAuthorizationChanged(new EventArgs());
        };
    }

    public event AuthorizationChangedEventHandler AuthorizationChanged;

    public void OnAuthorizationChanged(EventArgs e)
    {
        AuthorizationChanged?.Invoke(this, e);
    }
}

你知道这有一个可用的吗?:)现在:)我明天就试试这个谢谢@GeraldVersluis在这方面没有任何事件或功能。
public delegate void AuthorizationChangedEventHandler(object sender, EventArgs args);
public interface ILocation
{
    event AuthorizationChangedEventHandler AuthorizationChanged;

    void OnAuthorizationChanged(EventArgs e);
}
public class Location : ILocation    
{
    public Location()
    {
        var manager = new CLLocationManager();

        if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            manager.RequestWhenInUseAuthorization();

        manager.AuthorizationChanged += (sender, args) => {
            // Trigger event.
            OnAuthorizationChanged(new EventArgs());
        };
    }

    public event AuthorizationChangedEventHandler AuthorizationChanged;

    public void OnAuthorizationChanged(EventArgs e)
    {
        AuthorizationChanged?.Invoke(this, e);
    }
}