title: iOS CoreBluetooth updatevalue: and didUpdateValueForCharacteristic:
body: <p>I am developing an iOS app that communicates with a WT11i by bluegiga via Bluetooth 4.0<br>
  The iOS is running as the central while WT11i is acting as the peripheral.</p>
  
  <p>The characteristics of the service broadcast by WT11i is Write/Notify</p>
  
  <p>After my app is connected to the peripheral (WT11i), the peripheral will continuously send the value of a counter to my app.</p>
  
  <p>NSLog:</p>
  
  <pre><code>2013-09-18 14:22:58.843 IOS_Central[412:907] Receive -&gt; 1
  2013-09-18 14:22:58.904 IOS_Central[412:907] Receive -&gt; 2
  2013-09-18 14:22:58.963 IOS_Central[412:907] Receive -&gt; 3
  2013-09-18 14:22:59.023 IOS_Central[412:907] Receive -&gt; 4
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
  {
      receivingThings =true;
      if (error) {
          NSLog(@"Error discovering characteristics: %@", [error localizedDescription]);
          return;
      }
      NSString *newString = [[NSString alloc] initWithData:characteristic.value encoding:NSUTF8StringEncoding];
      NSLog(@"Receive -&gt; %@",newString);
  }
  </code></pre>
  
  <p>I can send a short message from my app to my peripheral using</p>
  
  <pre><code>-(void) sendToPeripheral:(NSString*)message{
      if(self.ConnectionState == CONNECTIONSTATE_NOTCONNECTED){
          return;
      }
     NSData *mainData1= [message dataUsingEncoding:NSUTF8StringEncoding];
      [self.connectedPeripheral writeValue:mainData1 forCharacteristic:self.connectedCharacteristic type:CBCharacteristicWriteWithResponse];
      NSLog(@"Send Message");
  }
  </code></pre>
  
  <p>Result of the writeValue: to Peripheral will be reflected here</p>
  
  <pre><code>- (void)peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error{
      if(error == nil){
          NSLog(@"Sent successfully");
      }
      else{
          NSLog(@"Send Fail");
      }
  }
  </code></pre>
  
  <p>When my peripheral received the message, it will acknowledge by sending an acknowledgement "Message Received" back to my app.</p>
  
  <p>Most of the time the communication is fine. However once in a while my app will miss an update right after I sent a message to the peripheral.</p>
  
  <pre><code>2013-09-18 14:22:58.843 IOS_Central[412:907] Receive -&gt; 1
  2013-09-18 14:22:58.904 IOS_Central[412:907] Receive -&gt; 2
  2013-09-18 14:22:58.963 IOS_Central[412:907] Receive -&gt; 3
  2013-09-18 14:22:59.023 IOS_Central[412:907] Receive -&gt; 4
  2013-09-18 14:22:59.050 IOS_Central[412:907] Send Message
  2013-09-18 14:22:59.083 IOS_Central[412:907] Receive -&gt; 5
  2013-09-18 14:22:59.113 IOS_Central[412:907] Sent successfully
  2013-09-18 14:22:59.143 IOS_Central[412:907] Receive -&gt; 7
  2013-09-18 14:22:59.203 IOS_Central[412:907] Receive -&gt; 8
  2013-09-18 14:22:59.263 IOS_Central[412:907] Receive -&gt; Message Received
  2013-09-18 14:22:59.322 IOS_Central[412:907] Receive -&gt; 9
  </code></pre>
  
  <p>Notice I did not receive number "6" from my peripheral?
  I have checked the logs on the peripheral, it says that it has sent out "6" to my app. My biggest suspicion lies in the iOS corebluetooth, where writeValue: clashes with didUpdateValueForCharacteristic:, therefore causing my "6" to be lost.</p>
  
  <p>Has anyone encountered this problem before too? Any suggestion?</p>