简体   繁体   English

如何为我的Xamarin.Forms iOS应用添加锁定屏幕?

[英]How can I add a lock screen to my Xamarin.Forms iOS app?

I am trying to add a lock screen to my iOS app such that "DidEnterBackground" will enable the lock "OnActivated". 我正在尝试将锁定屏幕添加到我的iOS应用中,以便“ DidEnterBackground”将启用锁定“ OnActivated”。 I've seen other apps do this using a PIN number, just wondering how to add that functionality to my app. 我见过其他应用使用PIN码执行此操作,只是想知道如何将该功能添加到我的应用中。

I'm using Xamarin.Forms Xamarin Studio 我正在使用Xamarin.Forms Xamarin Studio

I suspect there are many ways to do that, here's one suggestion. 我怀疑有很多方法可以做到这一点,这是一个建议。

Implement a service IDidDeactivate with an event in it, register it with the Resolver and when your Forms are initialized (App.cs) hook to that event and manipulate the navigation as needed, such as Navigation.PushModalAsync(new PinPad()) 实现一个带有事件的服务IDidDeactivate,在解析器中注册它,并在初始化窗体(App.cs)时挂接到该事件,并根据需要操纵导航,例如Navigation.PushModalAsync(new PinPad())

The code below is obviously trimmed down to the essence, I hope you get the idea 下面的代码显然是精简的,希望您能理解

// 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()); 
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM