Objective-C 如何将 NSArray 转换为 Byte 数组?

Objective-C how to convert a NSArray to Byte array?

我对 objective-c 不是很有经验,我需要为以下用例提供建议:

我正在为 ios 编写一个 React 本机模块,ios 端的一个本机方法接收到一个包含整数的 NSArray(每个整数的值介于 0 之间)和 255).

在我的 objective-c 代码中,我需要将此 NSArray 转换为 Byte bytes[] 以将其传递给我使用的某些 SDK。

我该如何转换?

NSArray* array = @[@(1), @(5), @(115), @(34)];

Byte* bytes = calloc(array.count, sizeof(Byte));

[array enumerateObjectsUsingBlock:^(NSNumber* number, NSUInteger index, BOOL* stop){

    bytes[index] = number.integerValue;
}];

doWhateverWithBytes(bytes);
free(bytes);

假设 doWhateverWithBytes 接受 Byte bytes[]