简体   繁体   English

如何检查用户的iOS设备是否支持蓝牙对等连接

[英]How To Check If A User's iOS Device Supports Bluetooth Peer-To-Peer Connections

What is the best way of programatically checking if the current device supports Bluetooth peer-to-peer GameKit connectivity? 以编程方式检查当前设备是否支持蓝牙对等GameKit连接的最佳方法是什么? I am aware of how to check for Game Center support, but want to support devices on iOS 3 that have Bluetooth (I know all devices with bluetooth can be upgraded to iOS 4). 我知道如何检查Game Center支持,但是想支持iOS 3上具有蓝牙的设备(我知道所有带有蓝牙的设备都可以升级到iOS 4)。

Edit : The app functions perfectly fine without Bluetooth, so I don't want peer-peer to be in UIRequiredDeviceCapabilities . 编辑 :该应用程序在没有蓝牙的情况下运行正常,因此我不希望peer-peer位于UIRequiredDeviceCapabilities

Many thanks in advance, 提前谢谢了,
jrtc27 jrtc27

Since we know which device supports what, if you can detect device you can make it work. 由于我们知道哪个设备支持什么功能,因此,如果您可以检测到设备,则可以使其正常运行。 I found this method and it works for me. 我找到了这种方法,它对我有用。 You can find device capabilities here . 您可以在此处找到设备功能

//Return TRUE if Device Support X. //如果设备支持X,则返回TRUE。

-(BOOL)platformSupported_X
{
NSString *platform = [self platform];
if ([platform isEqualToString:@"iPhone1,1"])    return FALSE;
if ([platform isEqualToString:@"iPhone1,2"])    return FALSE;
if ([platform isEqualToString:@"iPhone2,1"])    return TRUE;
if ([platform isEqualToString:@"iPhone3,1"])    return TRUE;
if ([platform isEqualToString:@"iPod1,1"])      return FALSE;
if ([platform isEqualToString:@"iPod2,1"])      return TRUE;
if ([platform isEqualToString:@"iPod3,1"])      return TRUE;
if ([platform isEqualToString:@"iPod4,1"])      return TRUE;
if ([platform isEqualToString:@"iPad1,1"])      return TRUE;
if ([platform isEqualToString:@"i386"])         return TRUE;
return TRUE;
}

// Check Device Model //检查设备型号

-(NSString *)platform
{
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithUTF8String:machine];
free(machine);
return platform;
}

There doesn't seem to be an elegant way to detect bluetooth peer-to-peer support based on the device type. 似乎没有一种优雅的方法可以根据设备类型检测蓝牙对等支持。 You might want to consider basing the detection on the OS version instead (iOS 3.1 is the minimum for peer-to-peer): 您可能需要考虑基于OS版本进行检测(iOS 3.1是对等网络的最低​​版本):

NSString *reqSysVer = @"3.1";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
BOOL osSupportsBluetoothPeerToPeer = ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending);

In case the OS is 3.1 or later, but the device does not support bluetooth peer-to-peer, the system will inform the user about the lack of support. 如果操作系统为3.1或更高版本,但设备不支持蓝牙对等网络,则系统将通知用户缺少支持。 This seems to be what Apple prefers: http://support.apple.com/kb/HT3621 这似乎是苹果公司更喜欢的: http : //support.apple.com/kb/HT3621

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM