不允许iOS集中书写 [英] iOS central writing is not permitted
问题描述
我是ios开发人员.我可以从arduino传感器中获取价值.但是我无法使用以下方法发送消息.
I am a ios developer. I can take a value from arduino sensor. But i cannot send a message by using the following the method.
[peripheral writeValue:dataToWrite forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];
通过使用 NSString
*
" dataToWrite
"值
and the following code is full code of "DiscoverCharacteristics in service"
下面的代码是服务中的发现特征"的完整代码
//DISCOVER CHAR
-(void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error
{
if (error) {NSLog(@"DISCOVER_CHAR - Error");return;}
NSString* data = @"1";
NSData* dataToWrite = [data dataUsingEncoding:NSUTF8StringEncoding];
for (CBCharacteristic * characteristic in service.characteristics) {
NSLog(@"DISCOVER_CHAR - Characteristic : %@",characteristic);
[peripheral writeValue:dataToWrite forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];
}
}
In this point, I want to summarize my question.
My Question is
"Even i used the [Peripheral writeValue:forCharacteristic:type
] Method. why an error message is shown in log monitor? " Like "Writing is not permitted."
在这一点上,我想总结一下我的问题.我的问题是即使我使用了[ Peripheral writeValue:forCharacteristic:type
]方法.为什么在日志监视器中显示错误消息呢?"就像"不允许写." >
我需要获得一些权限才能为Arduino写消息吗? OR ,我必须更改我的以下代码吗? OR 我在Arduino中遇到问题(实际上,Arduino可以从其他设备获取消息...因此,Arduino源代码很好.也许...)
Do i need to get some permission to writing the message for an Arduino? OR I have to change my following code? OR I have a problem in Arduino(Acutally, Arduino can get a message from other device... so, Arduino source code is fine. maybe...)
NSString* data = @"1";
NSData* dataToWrite = [data dataUsingEncoding:NSUTF8StringEncoding];
我有点像蓝牙菜鸟.因此,这可能是我已经忽略的显而易见的东西,但是任何帮助将不胜感激.
I'm a bit of a bluetooth noob. So it's probably something obvious I've overlooked but any help would be much appreciated.
谢谢!:)
推荐答案
非常感谢!!!!Paulw11.最后,我从iPhone向Arduino发送了数据.我检查了我特性的属性是< CB特性:0x13564a680,UUID = FFE1,属性= 0x16,值=(null),通知= NO>
.我的特征的属性= 0x16.但我找不到属性枚举中的0x16.不过,我不知道0x16的含义.有人说代表特征可能特性的值.由于可以组合特征特性,因此特征可以设置多个属性值."URL:解释特征属性(iOS和BLE).无论如何,我可以在PaulW11的帮助下找到解决方案!我该怎么办?这是我的解决方法.首先,我的方法是 [peripheral writeValue:dataToWrite forCharacteristic:characteristic * type:CBCharacteristicWriteWithResponse] *;
.问题代码是类型字段.我必须了解类型.该类型具有写,读等含义.因此,我将类型从 CBCharacteristicWriteWithResponse
更改为 CBCharacteristicPropertyWrite
.那就是我所做的. [外围设备的writeValue:dataToWrite forCharacteristic:characteristic * type:CBCharacteristicPropertyWrite *];
再次感谢你!Paulw11
Thank you a lot!!!!!!! Paulw11. Finally, i sent a data from iphone to Arduino. what i checked properties of my characteristic is
<CBCharacteristic: 0x13564a680, UUID = FFE1, properties = 0x16, value = (null), notifying = NO>
.
My characteristic's properties = 0x16. but i can not find a 0x16 in enum of properties. Still, I don't know the 0x16 meaning. Someone said that "Values representing the possible properties of a characteristic. Since characteristic properties can be combined, a characteristic may have multiple property values set."
URL: Interpret Characteristic Properties (iOS and BLE) .
Anyway I could find a solution by PaulW11 help! How i can do it? Here is my way of solution.
At first, My method is [peripheral writeValue:dataToWrite forCharacteristic:characteristic *type:CBCharacteristicWriteWithResponse]*;
.
The problem code is type field. I had to understand the type. The type has a meaning of write, read and so on. So, I changed the type from CBCharacteristicWriteWithResponse
to CBCharacteristicPropertyWrite
. That is what i did.
[peripheral writeValue:dataToWrite forCharacteristic:characteristic *type:CBCharacteristicPropertyWrite*];
Thank you again! Paulw11
这篇关于不允许iOS集中书写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!