UITextView被阻止因为外围设备:didUpdateValueForCharacteristic:被调用非常快

时间:2015-04-16 23:59:54

标签: ios core-bluetooth cbcentralmanager cbperipheral cbperipheralmanager

我试图通过附加来自peripheral:didUpdateValueForCharacteristic:error:的数据来在UITextView中显示数据。在这种情况下,peripheral:didUpdateValueForCharacteristic:error:被频繁调用,因为UITextViewself.responseTextView)无法打印任何数据或阻止用户界面。

- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
{
    if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:UNKNOWN3_CHARACTERISTICS]]) 
   {
        NSData *data = characteristic.value;
        NSString *stringFromData = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        self.responseTextView.text = [self.responseTextView.text stringByAppendingString:stringFromData];
        NSLog(@"%@",stringFromData);
    }
}

0 个答案:

没有答案