除了进行模型检查之外,我不确定是否有办法做到这一点,这可能不是一个好方法.我知道苹果提供:
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
Run Code Online (Sandbox Code Playgroud)
如果设备可以振动,它会.在没有振动的设备上,它什么都不做.还有一个电话:
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
Run Code Online (Sandbox Code Playgroud)
如果设备散列该设备或设备将发出蜂鸣声,则此设备将振动设备.
最好只进行设置并对设置进行一些解释,因为用户在没有振动设备时可能需要发出蜂鸣声.也许可以将设置称为"振动警报开/关"以外的设置.
这段代码应该可以做到这一点 - 请注意,它“假设”iPhone 是唯一具有振动功能的设备。目前是这样......
- (NSString *)machine
{
static NSString *machine = nil;
// we keep name around (its like 10 bytes....) forever to stop lots of little mallocs;
if(machine == nil)
{
char * name = nil;
size_t size;
// Set 'oldp' parameter to NULL to get the size of the data
// returned so we can allocate appropriate amount of space
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
// Allocate the space to store name
name = malloc(size);
// Get the platform name
sysctlbyname("hw.machine", name, &size, NULL, 0);
// Place name into a string
machine = [[NSString stringWithUTF8String:name] retain];
// Done with this
free(name);
}
return machine;
}
-(BOOL)hasVibration
{
NSString * machine = [self machine];
if([[machine uppercaseString] rangeOfString:@"IPHONE"].location != NSNotFound)
{
return YES;
}
return NO;
}
Run Code Online (Sandbox Code Playgroud)
刚刚进行编辑以阻止机器调用每次调用时执行大量小型 malloc。
| 归档时间: |
|
| 查看次数: |
1617 次 |
| 最近记录: |