菜鸟教程小白 发表于 2022-12-12 09:44:03

ios - Corebluetooth 为特征写入十六进制值


                                            <p><p>我正在尝试为一个特性编写十六进制值 <code>NSString * const SET_BUZZER_ON = @"0xef";</code> 而方法 <code>didDiscoverCharacteristicsForService</code> 被调用,我检查我是否然后在正确的特征中:</p>

<pre><code>NSData* valData = ;
;
</code></pre>

<p>代码执行没有问题,但是当方法 <code>didWriteValueForCharacteristic</code> 被调用时,我得到了错误:</p>

<pre><code>Error writing characteristic value: The value&#39;s length is invalid.
</code></pre>

<p>有什么想法吗?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我刚刚想通了,我必须用 <code>Bytes Array</code> 而不是 <code>NSString</code> 来初始化 <code>NSData</code>:</p>

<pre><code>const uint8_t bytes[] = {0xef};
NSData *valData = ;
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - Corebluetooth 为特征写入十六进制值,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/33694342/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/33694342/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - Corebluetooth 为特征写入十六进制值