在iOS中NSData转Byte,见到最多的NSData转Byte的就是
NSString *string = @"111111";
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
Byte *testByte = (Byte *)[data bytes];
但是这种方法常常是不可行的,这时候就要换个方法了,
NSString *codeKey = @"111111111";
NSData *codeKeyData = [codeKey dataUsingEncoding:NSUTF8StringEncoding];
Byte codeKeyByteAry[codeKeyData.length];
for (int i = 0 ; i < codeKeyData.length; i++) {
NSData *idata = [codeKeyData subdataWithRange:NSMakeRange(i, 1)];
codeKeyByteAry[i] =((Byte*)[idata bytes])[0];
}
OK !