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

发布于 2024-12-06 17:31:45 字数 272 浏览 1 评论 0 原文

以编程方式检查当前设备是否支持蓝牙点对点 GameKit 连接的最佳方法是什么?我知道如何检查 Game Center 支持,但想要支持具有蓝牙功能的 iOS 3 设备(我知道所有具有蓝牙功能的设备都可以升级到 iOS 4)。

编辑:该应用程序在没有蓝牙的情况下也可以正常运行,因此我不希望 peer-peer 位于 UIRequiredDeviceCapability 中。

非常感谢,
jrtc27

What is the best way of programatically checking if the current device supports Bluetooth peer-to-peer GameKit connectivity? 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).

Edit: The app functions perfectly fine without Bluetooth, so I don't want peer-peer to be in UIRequiredDeviceCapabilities.

Many thanks in advance,
jrtc27

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

﹂绝世的画 2024-12-13 17:31:45

因为我们知道哪个设备支持什么,如果您可以检测到设备,就可以使其工作。我发现了这个方法并且它对我有用。您可以找到 此处的设备功能

//如果设备支持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;
}

//检查设备型号

-(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;
}

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.

-(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;
}
寒江雪… 2024-12-13 17:31:45

似乎没有一种优雅的方法来根据设备类型检测蓝牙对等支持。您可能需要考虑基于操作系统版本进行检测(iOS 3.1 是点对点的最低版本):

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

如果操作系统为 3.1 或更高版本,但设备不支持蓝牙点对点,则系统将通知用户缺少支持。这似乎是苹果更喜欢的: http://support.apple.com/kb/HT3621

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):

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. This seems to be what Apple prefers: http://support.apple.com/kb/HT3621

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文