【发布时间】:2017-03-17 11:18:55
【问题描述】:
我想在手机设置中禁用触觉反馈时在我的应用程序中显示消息。如何检测在设备设置中禁用了触觉反馈?
【问题讨论】:
标签: ios objective-c xcode vibration
我想在手机设置中禁用触觉反馈时在我的应用程序中显示消息。如何检测在设备设置中禁用了触觉反馈?
【问题讨论】:
标签: ios objective-c xcode vibration
这很笨拙,但这可行吗?
- (BOOL)isHapticFeedbackDisabled {
BOOL result = NO;
UISelectionFeedbackGenerator *feedbackGenerator = [[UISelectionFeedbackGenerator alloc] init];
[feedbackGenerator prepare];
if ([feedbackGenerator.description containsString:@"prepared=0"]) result = YES;
feedbackGenerator = nil;
return result;
}
【讨论】:
无法检查触觉反馈是否启用/禁用,但 UIKit 中有私有 int _feedbackSupportLevel 用于检查设备是否支持它:
func logFeedbackSupported() {
let supportLevel = UIDevice.current.value(forKey: "_feedbackSupportLevel")
print(supportLevel ?? "")
}
0:不可用, 1:第一代可用(2:第二代可用。
我建议你不要使用 Apple 的私有 API,因为:
【讨论】: