Я использую GCDWebServer для создания HTTP-сервера на своем устройстве. Фактический контент для веб-страницы помещается в папку «Документы» моего приложения. Содержимое содержит файл HTML с указанными файлами css и png. Проблема в том, что файлы css и png недоступны/используются с сервера (я вижу только текстовое содержимое HTML).
Соответствующий код:
self.server = [[GCDWebServer alloc] init];
NSString *documents = [[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject] absoluteString];
documents = [documents stringByAppendingPathComponent:@"MyWebsite"];
[self.server addGETHandlerForBasePath:@"/" directoryPath:documents indexFilename:nil cacheAge:0 allowRangeRequests:YES];
__weak typeof(self) weakSelf = self;
[_server addDefaultHandlerForMethod:@"GET" requestClass:[GCDWebServerRequest class] processBlock:^GCDWebServerResponse *(GCDWebServerRequest *request) {
if ([[request path] isEqualToString:@"/status"]) {
return [GCDWebServerDataResponse responseWithText:@"RUNNING"];
}
else if ([[request path] isEqualToString:@"/"]) {
NSString *filePath = [documents stringByAppendingPathComponent:@"mypage.html"];
NSString *html = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
return [GCDWebServerDataResponse responseWithHTML:html];
}
return nil;
}];
[self.server startWithOptions:@{GCDWebServerOption_Port: @(80)} error:&error];
Спасибо!