如何使用GameKit蓝牙将NSDictionary(或plist文件)作为NSData发送? [英] How to send an NSDictionary (or plist file) as NSData using GameKit bluetooth?
本文介绍了如何使用GameKit蓝牙将NSDictionary(或plist文件)作为NSData发送?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用
[currentSession sendDataToAllPeers:data withDataMode:GKSendDataReliable error:nil];
将包含数据的NSDictionary(或plist文件)从一台设备发送到另一台设备,并且
to send an NSDictionary (or a plist file) containing data from 1 device to another, and
- (void)receiveData:(NSData *)data fromPeer:(NSString *)peer inSession:(GKSession *)session context:(void *)context
接收它.我该如何与NSData进行相互转换?
to receive it. How can I convert to and from NSData for this to happen?
推荐答案
您可以使用以下命令将Plist转换为NSData:
You can use the following to transform Plist to NSData:
+ (NSData *)dataWithPropertyList:(id)plist
format:(NSPropertyListFormat)format
options:(NSPropertyListWriteOptions)opt
error:(NSError **)error
然后将NSData转换为Plist:
And this to transform NSData to Plist:
+ (id)propertyListWithData:(NSData *)data
options:(NSPropertyListReadOptions)opt
format:(NSPropertyListFormat *)format
error:(NSError **)error
of <代码> NSPropertyListSerialization 类
format
可以是 NSPropertyListBinaryFormat_v1_0
以使用最低字节数
format
could be NSPropertyListBinaryFormat_v1_0
to use lowest byte count
这篇关于如何使用GameKit蓝牙将NSDictionary(或plist文件)作为NSData发送?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文