In the docs it is clearly stated that you need an implementation for all platforms:
You must provide an implementation in every platform project. If no Interface implementation is registered, then the
DependencyService
will be unable to resolve theGet<T>()
method at runtime.
I haven't provided an implementation and so the app crashed. But what should I do in the case, that I don't need an implementation for that platform? Providing a bodyless method like this?
public void HideKeyboard()
{
// We need an implementation for the DependencyService, even it is empty.
}
Should I provide an implementation nevertheless?
public void HideKeyboard()
{
try
{
InputPane myInputPane = InputPane.GetForCurrentView();
myInputPane.TryHide();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
}
Or is the use of DependencyService
the wrong option here?