如何检查 iOS 设备是否可以振动
目前只有 iPhone 支持振动,如何在调用振动功能之前检查我的设备是否支持振动。
Currently only iPhone supports the vibrations how can I check if my device supports vibrations before calling the vibration function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
iOS sdk 有两个可以让 iPhone 振动的函数。但振动硬件仅出现在 iPhone 上。那么,您将如何提醒在 iPad 或 iPod touch 上使用该应用程序的用户呢?显然,检查模型并不是正确的方法。有两个看似相似的函数,它们都采用 kSystemSoundID_Vibrate 参数,
这两个函数都会使 iPhone 振动。但当您在不支持振动的设备上使用第一个功能时,它会发出嘟嘟声。另一方面,第二个函数在不受支持的设备上不执行任何操作。
The iOS sdk has two functions that would vibrate the iPhone. But Vibration hardware is present only on iPhones. So how will you alert your user who uses the app on iPad or iPod touches? Clearly, checking the model is not the way to go. There are two seemingly similar functions that take a parameter kSystemSoundID_Vibrate
Both the functions vibrate the iPhone. But when you use the first function on devices that don’t support vibration, it plays a beep sound. The second function on the other hand does nothing on unsupported devices.
有点解决办法,但我发现这是可行的。它基于目前只有 iPhone 设备配备振动硬件的假设。
A bit of a work-around but I've found this to work. It's based on the assumption that only iPhone devices currently have the vibrate hardware in them.
不幸的是,没有记录的方法来测试设备是否支持振动。来自文档:
看起来这里正确的方法是简单地调用 Saurabh 提到的方法,而不检查是否支持振动。
Unfortunately there is no documented method for testing whether or not the device supports vibration. From documentation:
Looks like the correct approach here would be to simply call the methods mentioned by Saurabh without checking if vibration is supported.