簡體   English   中英

如何為我的Xamarin.Forms iOS應用添加鎖定屏幕?

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

我正在嘗試將鎖定屏幕添加到我的iOS應用中,以便“ DidEnterBackground”將啟用鎖定“ OnActivated”。 我見過其他應用使用PIN碼執行此操作,只是想知道如何將該功能添加到我的應用中。

我正在使用Xamarin.Forms Xamarin Studio

我懷疑有很多方法可以做到這一點,這是一個建議。

實現一個帶有事件的服務IDidDeactivate,在解析器中注冊它,並在初始化窗體(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()); 
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM