在Xamarin IOS中,我可以使用以下设备振动:
SystemSound.Vibrate.PlaySystemSound();
但是,如果设备不支持振动,这简直什么都没有,iPad设备当前就是这种情况。
有没有办法查找设备上是否支持振动?
您可以检查TargetIdiom
:
if(Device.Idiom.Equals(TargetIdiom.Phone))
{
// vibrate supported because only iPhone can vibrate
}
,但请记住,这是一个解决方法。
iOS中没有任何东西可以检查设备是否支持振动。根据Apple文档,KsystemsoundID_Vibrate(振动)仅在iPhone上起作用 - 不在iPod上,而不是在iPad上。
因此,您必须检查当前设备是否为iPhone才能检查是否支持振动:
if(Device.Idiom.Equals(TargetIdiom.Phone))
{
// you can play vibrate sound.
}
else
{
//play other sound
}