我正在尝试为我的iOS应用添加锁定屏幕,以便“DidEnterBackground”将启用锁定“OnActivated”。我见过其他应用程序使用PIN码执行此操作,只是想知道如何将该功能添加到我的应用程序。
我正在使用Xamarin.Forms Xamarin Studio
答案 0 :(得分:0)
我怀疑有很多方法可以做到这一点,这是一个建议。
使用其中的事件实现服务IDidDeactivate,将其注册到Resolver,并在初始化Forms(App.cs)时挂钩该事件并根据需要操作导航,例如Navigation.PushModalAsync(new PinPad())
下面的代码显然已经明确了,我希望你能得到这个想法
// this goes in the Forms project
public interface IDidDeactivate{
event EventHandler Deactivated;
event EventHandler Activated;
}
//this goes in the iOS project
public class WhoDeactivated: IDidDeactivate{
public event EventHandler Deactivated;
public event EventHandler Activated;
public void SendEvent (bool isActivated){
if (isActivated)
Activated(this, new EventArgs());
else
Dectivated(this, new EventArgs());
}
}
// back to the Forms project:
public class SensitivePage: ContentPage{
public SensitivePage(){
var deactivateService = Resolver.Resolve<IDidDeactivate>();
deactivateService.Deactivated += (s,e)=>
Navigation.PushModalAsync(new PinPadPage());
}
}