多对等连接:同时将文件共享给所有对等 [英] Multipeer Connectivity : Share Files to all peers simultaneously

查看:159
本文介绍了多对等连接:同时将文件共享给所有对等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究主题多对等连接框架.使用以下链接,我对这个框架有了一个很好的主意:

I'am working on a topic multipeer connectivity framework. I got a great idea about this framework using the below link :

http://www.appcoda.com/intro-multipeer -connectivity-framework-ios-programming/

但是我的问题是,我可以向所有连接的对等方发送聊天消息并被他们接收.但是我在文件共享中需要相同的功能.我需要同时将文件发送到所有连接的对等方.有可能吗???

But my problem is ,i can send chat messages to all connected peers and is received by them. But i need that same functionality in File sharing. I need to send files simultaneously to all connected peers. Is that possible????

推荐答案

是的,有可能.如果要发送大文件(例如数十兆字节或更多),我建议使用方法sendResourceAtURL:withName:toPeer:withCompletionHandler`` instead of sendData:toPeers:withMode:error:`.

Yes, it is possible. If you want to send large files (like tens of megabytes or more) I would recommend using method sendResourceAtURL:withName:toPeer:withCompletionHandler`` instead ofsendData:toPeers:withMode:error:`.

这样,您不必一次将整个文件加载到内存中(这可能会触发内存警告甚至崩溃).另外,您还会获得NSProgress作为返回值,以便向用户显示传输进度.

This way you don't have to load the whole file to memory at once (which may trigger a memory warning or even a crash). Also you get a NSProgress as a returned value, so you can show transfer's progress to the user.

NSURL* fileUrl = [NSURL fileURLWithPath:...];   //get the path of the file you'd like to send
    NSString* resourceName = @"<name to display>";
    for(MCPeerID *peer in session.connectedPeers) {
        [session sendResourceAtURL:fileUrl withName:resourceName toPeer:peer withCompletionHandler:^(NSError *error) {
            //handle transfer completion or error
        }];
    }

这篇关于多对等连接:同时将文件共享给所有对等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆