iphone编程中如何通过蓝牙发送图像?
我是一些 NSString,我只是加入它们并制作一个 NSString,然后我将该单个 NSString 转换为 NSData 并通过蓝牙发送到其他 iphone,
但现在我必须发送带有上述数据的图像,
我怎样才能实现这样的概念?
但我想发送单个 NSData (UIImage+NSString),我该怎么办???
I am some NSStrings, and I am just joining them and making a single NSString, then I am converting that single NSString to NSData and sending via bluetooth to other iphone
but now I have to send image with above data,
how can I achieve such concept ?
but I want to send single NSData (UIImage+NSString), how can I ????
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有关如何在 iPhone 上编程蓝牙数据传输的教程在这里:
http://www.devx.com/wireless/Article/43502/1954
您正在寻找的重要部分就在这里:
祝您好运!
a tutorial on how to program Bluetooth data transfer on the iPhone is here:
http://www.devx.com/wireless/Article/43502/1954
The essential part you're looking for is here:
Good luck with it!
我建议以单独的数据包发送它们,因为图像可能非常大(以多个数据包发送图像本身)。但如果你真的想一次性完成所有工作,请尝试将它们包装在 NSDictionary 中。将字典编码为 NSData,然后发送出去。
像下面这样的东西会起作用。
NSDictionary *myDict = //无论你的字典应该在这里保存什么...
NSMutableData *packet = [[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc]initForWritingWithMutableData:packet];
[存档器encodeObject:myDict forKey:@“SomeKey”];
[存档完成编码];
I would recommend sending them in separate packets since an image could be quite large (send the image itself in multiple packets). But if you really want to do it all at once, try wrapping them in an NSDictionary. Encode the dictionary into NSData, and send it off.
Something like the following would work.
NSDictionary *myDict = //whatever your dict should hold here...
NSMutableData *packet = [[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc]initForWritingWithMutableData:packet];
[archiver encodeObject:myDict forKey:@"SomeKey"];
[archiver finishEncoding];