title: How to block code to wait for a connection
body: <p>Ive been boxing around with a new api for some sensorTag. I need to wait for the connection to settle or my code piece will fail the first time tis ran. I have the following code snippet:</p>
  
  <pre><code>- (void)viewDidLoad {
  [super viewDidLoad];
  
  self.sensorGyro = [MSBSensorUV createObjectGyro];
  if(self.sensorGyro){
      while (!self.sensorGyro.client.isDeviceConnected) {
          NSLog(@"Awaiting connection");
      }//Check that connection has been made
  
      NSLog(@"connection UP");
  
          [self.sensorGyro.client.sensorManager startGyroUpdatesToQueue:nil errorRef:nil withHandler:^(MSBSensorGyroData *GyroData, NSError *error) {
              NSLog(@"Starting updates");
              self.currentGyroLabel.text = [NSString stringWithFormat:@"%lu", GyroData.GyroIndexLevel];
          }];
  </code></pre>
  
  <p>Initially I didn't have the while loop. I used a 2-3sec dispatch_after call. But I felt it was not good waiting a fixed time, better would be to proceed when connected. But When I use the while loop my app just stalls and stops working. no crash, just stop. Can anybody tell me why this is happening. since I have verified the connection only takes like 2 sec, I don't see a problem doing the while loop? Also, is there a better way to "wait" for stuff to finish/get dry.</p>
  
  <p>Thanks in advance</p>