Send NSString via Game Center

前端 未结 2 1527
心在旅途
心在旅途 2021-01-29 02:28

I want to send NSString form another one to another one iPhone/iPad via Gamecenter but it crash with EXC_BAD_ACCESS

here in .h file

typedef enum {
    kM         


        
2条回答
  •  孤街浪徒
    2021-01-29 03:00

    try this:

    To encode:

    NSData *data = [stringToEncode dataUsingEncoding:NSUTF8Encoding];
    

    which you can send using Game Center

    To decode:

    NSString *recievedString = [NSString stringWithUTF8String:[recievedData bytes]];
    

    Edit: Now I think you can even put this data in one of your message structs and do the same [NSData dataWithBytes:&message length:sizeof(MessageSubmit)] trick and send it.

提交回复
热议问题