Создание интерфейса в базовом проекте:
public interface IDevicePlatform
{
bool IsSimulator();
}
iOS DependencyService Регистрация / внедрение:
public class Platform_iOS : IDevicePlatform
{
public IsSimulator()
{
return ObjCRuntime.Runtime.Arch == ObjCRuntime.Arch.SIMULATOR;
}
}
Android DependencyService Регистрация / Внедрение:
public class Platform_Android : IDevicePlatform
{
public bool IsSimulator()
{
if (Build.Fingerprint != null)
{
if (Build.Fingerprint.Contains("vbox") || Build.Fingerprint.Contains("generic") || Build.Fingerprint.Contains("vsemu"))
return true;
}
return false;
}
}
Назовите его в Core как:
bool isSimulator = DependencyService.Get<IDevicePlatform>().IsSimulator();
if(isSimulator)
{
//You are running on the Simulator
}
else
{
//You are running on the real device
}
ПРИМЕЧАНИЕ : реализация iOS проста, а Androidширокий мир, так что, помимо простой реализации для Android, посмотрите также SushiHangover's Answer