iphone编程中如何通过蓝牙发送图像?

发布于 2024-10-30 04:30:11 字数 189 浏览 1 评论 0原文

我是一些 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空城旧梦 2024-11-06 04:30:11

有关如何在 iPhone 上编程蓝牙数据传输的教程在这里:
http://www.devx.com/wireless/Article/43502/1954

您正在寻找的重要部分就在这里:

-(IBAction) btnSend:(id) sender
{
    //---convert an NSString object to NSData---
    NSData* data;
    NSString *str = [NSString stringWithString:txtMessage.text];
    data = [str dataUsingEncoding: NSASCIIStringEncoding];        
    [self mySendDataToPeers:data];        
}

- (void) mySendDataToPeers:(NSData *) data
{
    if (currentSession) 
        [self.currentSession sendDataToAllPeers:data 
                                   withDataMode:GKSendDataReliable 
                                          error:nil];    
}

祝您好运!

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:

-(IBAction) btnSend:(id) sender
{
    //---convert an NSString object to NSData---
    NSData* data;
    NSString *str = [NSString stringWithString:txtMessage.text];
    data = [str dataUsingEncoding: NSASCIIStringEncoding];        
    [self mySendDataToPeers:data];        
}

- (void) mySendDataToPeers:(NSData *) data
{
    if (currentSession) 
        [self.currentSession sendDataToAllPeers:data 
                                   withDataMode:GKSendDataReliable 
                                          error:nil];    
}

Good luck with it!

护你周全 2024-11-06 04:30:11

我建议以单独的数据包发送它们,因为图像可能非常大(以多个数据包发送图像本身)。但如果你真的想一次性完成所有工作,请尝试将它们包装在 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];

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文