Как скачать файл с iOS?

Мое приложение хочет запустить один http-сервер, и другие устройства могут загружать файлы с него.

Я использую какао 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]; 
        }

Когда я загружаю тестовый файл в веб-документ, его размер всегда составляет o байт.

0 ответов

Другие вопросы по тегам