简体   繁体   English

如何将 NSData 转换为 const uint8_t?或在通过 Wifi 传递 NSData 时出错

[英]How can i convert NSData to const uint8_t?or getting error while passing a NSData over Wifi

i have a array with two strings:我有一个包含两个字符串的数组:

NSArray *sendingArray = [[NSArray alloc]initWithObjects:@"CAT",@"DOG",nil];

and i converted the array to NSData:我将数组转换为 NSData:

NSData *myData = [NSKeyedArchiver archivedDataWithRootObject:sendingArray];

now i need to convert my NSData(myData) to const uint8_t现在我需要将我的NSData(myData)转换为const uint8_t

i am doing this code to send an array of values through Wifi network.我正在执行此代码以通过 Wifi 网络发送一组值。

i send successfully a string over wifi using the below code(my string is "string").我使用下面的代码通过wifi成功发送了一个字符串(我的字符串是“字符串”)。

 const uint8_t *message = (const uint8_t *)[string UTF8String]; 

    [_outStream write:bytes maxLength:len];

i wrote the below code to send NSData object but it got error.我写了下面的代码来发送 NSData object 但它出错了。

code is:代码是:

const uint8_t *bytes = (uint8_t)[myData bytes];//this line getting error.
    [_outStream write:bytes maxLength:len];

can i send my NSData(myData) through the above method without converting it to const uint8_t?我可以通过上述方法发送我的NSData(myData)而不将其转换为 const uint8_t 吗? if yes,please give me the code that i need to write.如果是,请给我需要编写的代码。

or can any one tell me the way to convert my NSData(myData) to const uint8_t或者任何人都可以告诉我将我的NSData(myData)转换为const uint8_t的方法

 const uint8_t *bytes = (const uint8_t*)[myData bytes];
 //                                   ^^ note the asterisk

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM