2014-02-15 155 views
2

我正在與iOS中央處理器進行通信,以便與BLE外圍設備進行通信。CoreBluetooth讀取/寫入數據

使用LGBluetooth框架https://github.com/DavidSahakyan/LGBluetooth

的方法得到

 
     [LGUtils readDataFromCharactUUID:aCharactId 
           seriveUUID:aServiceId 
           peripheral:peripheral 
           completion:^(NSData *data, NSError *error) { 
            NSLog(@"Data : %s Error : %@", (char *)[data bytes], error); 
           }]; 

它輸出 「1234567890」

我需要轉換(字符*)[數據字節]來NSInteger的。 當我得到它

 
     NSInteger dataInt = [data bytes]; 

我得到2013527536,但該值是1234567890的周側

+0

上面的鏈接不起作用 – DAMM108

回答

1

嘗試做這樣的事情:

NSInteger dataInt = atoi((const char*)[data bytes]); 
+0

我用atol((const char *)[data bytes]) – l0gg3r