我正在使用带有警报通知服务的 iOS 6 Corebluetooth。
尽管委托(delegate)方法中的 advertisingData 看起来是正确的,但出于某种原因这些服务没有出现在外围设备中。
这是委托(delegate)方法:
(void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
bool ourGuy = NO;
NSLog(@"DATA: %@", advertisementData);
NSArray *keys = [advertisementData allKeys];
for (int i = 0; i < [keys count]; ++i) {
id key = [keys objectAtIndex: i];
NSString *keyName = (NSString *) key;
NSObject *value = [advertisementData objectForKey: key];
if ([value isKindOfClass: [NSArray class]]) {
printf(" key: %s\n", [keyName cStringUsingEncoding: NSUTF8StringEncoding]);
if ([keyName isEqualToString: @"kCBAdvDataServiceUUIDs"] ){
NSArray *values = (NSArray *) value;
for (int j = 0; j < [values count]; ++j) {
if ([[values objectAtIndex: j] isKindOfClass: [CBUUID class]]) {
CBUUID *uuid = [values objectAtIndex: j];
NSString *uuidString = [uuid representativeString];
NSLog(@"FOUND SERVICE UUID %@", uuidString);
if ([uuidString isEqualToString:kalertNotificationServiceUUIDString]){
NSLog(@"Connecting");
if (![foundPeripherals containsObject:peripheral]) {
ourGuy = YES;
}
}
} else {
const char *valueString = [[value description] cStringUsingEncoding: NSUTF8StringEncoding];
printf(" value(%d): %s\n", j, valueString);
}
}
}
} else {
const char *valueString = [[value description] cStringUsingEncoding: NSUTF8StringEncoding];
printf(" key: %s, value: %s\n", [keyName cStringUsingEncoding: NSUTF8StringEncoding], valueString);
}
}
if (ourGuy){
[foundPeripherals addObject:peripheral];
peripheral.delegate = self;
[centralManager connectPeripheral:peripheral options:nil];
}
}
这是日志的样子:
2013-08-25 23:30:17.417 myControl[688:907] DATA: {
kCBAdvDataLocalName = myTEST;
kCBAdvDataServiceUUIDs = (
"Unknown (<1811>)",
"Unknown (<180f>)"
);
}
key: kCBAdvDataServiceUUIDs
2013-08-25 23:30:17.419 myControl[688:907] FOUND SERVICE UUID 1811
2013-08-25 23:30:17.421 myControl[688:907] Connecting
2013-08-25 23:30:17.422 myControl[688:907] FOUND SERVICE UUID 180f
key: kCBAdvDataLocalName, value: myTEST
key: kCBAdvDataTxPowerLevel, value: -8
服务发现的委托(delegate)方法:
- (void) peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error{
for (int i=0; i < peripheral.services.count; i++) {
CBService *s = [peripheral.services objectAtIndex:i];
NSLog(@" UUUID %@", [s.UUID representativeString]);
// [peripheral discoverCharacteristics:nil forService:s];
}
}
该方法的日志:
2013-08-25 23:30:18.266 myControl[688:907] UUUID 1800
2013-08-25 23:30:18.269 myControl[688:907] UUUID 1801
这是 BLE GATT 和 GAP 的两个 UUID。在 advertisementData 中看到的外设服务永远不会出现。我做错了什么?
最佳答案
关于您的代码:您是否实现了 peripheral:didDiscoverServices: 回调,您如何处理它?在最简单的情况下,它应该是这样的:
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error {
/* Find all characteristics for all discovered services */
for (CBService *service in peripheral.services)
{
[peripheral discoverCharacteristics:nil forService:service];
}
}
此外,广告数据中的内容和提供的内容是两个不同的故事。外围设备可以宣传任何服务,甚至是那些没有提供的服务我可以像这样在 iOS 中轻松开始广告:
NSDictionary *data = @{CBAdvertisementDataServiceUUIDsKey:
@[[CBUUID UUIDWithString:@"180D"], [CBUUID UUIDWithString:@"FFBC"]]};
[peripheralManager startAdvertising:data];
不添加任何这些服务。
我建议您首先尝试使用可正常运行的应用程序(例如 BLEUtility 或 BLExplr)来发现外围设备,然后查看外围设备是否真的在提供这些服务。
关于iOS Corebluetooth 服务从未被发现,但在委托(delegate)方法的广告数据中可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18430738/
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
我正在尝试使用ruby和Savon来使用网络服务。测试服务为http://www.webservicex.net/WS/WSDetails.aspx?WSID=9&CATID=2require'rubygems'require'savon'client=Savon::Client.new"http://www.webservicex.net/stockquote.asmx?WSDL"client.get_quotedo|soap|soap.body={:symbol=>"AAPL"}end返回SOAP异常。检查soap信封,在我看来soap请求没有正确的命名空间。任何人都可以建议我
我正在尝试设置一个puppet节点,但rubygems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由rubygems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby
我想安装一个带有一些身份验证的私有(private)Rubygem服务器。我希望能够使用公共(public)Ubuntu服务器托管内部gem。我读到了http://docs.rubygems.org/read/chapter/18.但是那个没有身份验证-如我所见。然后我读到了https://github.com/cwninja/geminabox.但是当我使用基本身份验证(他们在他们的Wiki中有)时,它会提示从我的服务器获取源。所以。如何制作带有身份验证的私有(private)Rubygem服务器?这是不可能的吗?谢谢。编辑:Geminabox问题。我尝试“捆绑”以安装新的gem..
我想了解Ruby方法methods()是如何工作的。我尝试使用“ruby方法”在Google上搜索,但这不是我需要的。我也看过ruby-doc.org,但我没有找到这种方法。你能详细解释一下它是如何工作的或者给我一个链接吗?更新我用methods()方法做了实验,得到了这样的结果:'labrat'代码classFirstdeffirst_instance_mymethodenddefself.first_class_mymethodendendclassSecond使用类#returnsavailablemethodslistforclassandancestorsputsSeco
我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer
设置:狂欢ruby1.9.2高线(1.6.13)描述:我已经相当习惯在其他一些项目中使用highline,但已经有几个月没有使用它了。现在,在Ruby1.9.2上全新安装时,它似乎不允许在同一行回答提示。所以以前我会看到类似的东西:require"highline/import"ask"Whatisyourfavoritecolor?"并得到:Whatisyourfavoritecolor?|现在我看到类似的东西:Whatisyourfavoritecolor?|竖线(|)符号是我的终端光标。知道为什么会发生这种变化吗? 最佳答案
我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby1.9+ 关于ruby-主要:Objectwhenrun