如何从iOS下载文件?

时间:2013-03-14 10:43:08

标签: ios cocoahttpserver

我的应用程序想运行一个http服务器,其他设备可以从中下载文件。

我正在使用cocoa http服务器并关注:https://github.com/robbiehanson/CocoaHTTPServer/blob/master/Samples/DynamicServer/MyHTTPConnection.m

我的http连接是:

@implementation MyHTTPConnection

- (NSObject<HTTPResponse> *)httpResponseForMethod:(NSString *)method URI:(NSString *)path
{

    NSString *filePath = [self filePathForURI:path];

    // Convert to relative path

    NSString *documentRoot = [config documentRoot];

    NSString *relativePath = [filePath substringFromIndex:[documentRoot length]];

    NSLog(@"file path is %@", filePath);

    //return [super httpResponseForMethod:method URI:path];
    return [[HTTPFileResponse alloc] initWithFilePath:filePath forConnection:self];
}
@end

代表中的代码是:

        httpServer = [[HTTPServer alloc] init];

        [httpServer setConnectionClass:[MyHTTPConnection class]];


        [httpServer setType:@"_http._tcp."];
        NSString *webPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"web"];
        if(webPath){
            NSString * ip = '192.168.1.10';

            int port = 3321;
            [httpServer setDocumentRoot:webPath];
            [httpServer setPort:port];
            [httpServer setInterface: ip];
            [self startServer]; 
        }

当我在web文档中下载测试文件时,大小总是为o字节。

0 个答案:

没有答案