上节 DLNA(二)我们说了 对于DLNA的网络的资源投屏,但是要实现本地的,还是需要其他的方式
看到网上有人使用Platinum 在本地搭建服务器,结果看到的是C++代码实现
那我们就换种方式,使用GCDWebServer/WebDAV三方来实现(里面是OC的框架哟)
下面我就贴出关键的代码:具体的实现可参考gitHubDemo里面的具体的包括实现都有具体的实现
本地视频网络话:
__weak typeof(self) weakSelf = self;
NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
self.davServer = [[GCDWebDAVServer alloc] initWithUploadDirectory:documentsPath];
self.davServer.delegate = self;
[self.davServer addHandlerForMethod:@"GET" pathRegex:@"/video.mov" requestClass:[GCDWebServerRequest class] asyncProcessBlock:^(__kindof GCDWebServerRequest * _Nonnull request, GCDWebServerCompletionBlock _Nonnull completionBlock) {
GCDWebServerFileResponse *res = [GCDWebServerFileResponse responseWithFile:weakSelf.currentStr byteRange:request.byteRange];
completionBlock(res);
}];
[self.davServer start];
本地图片网络话:
NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
self.davServer = [[GCDWebDAVServer alloc] initWithUploadDirectory:documentsPath];
self.davServer.delegate = self;
__weak typeof (self) weakSelf = self;
[self.davServer addHandlerForMethod:@"GET" pathRegex:@"myImage" requestClass:[GCDWebServerRequest class] asyncProcessBlock:^(__kindof GCDWebServerRequest * _Nonnull request, GCDWebServerCompletionBlock _Nonnull completionBlock) {
GCDWebServerDataResponse *response = [GCDWebServerDataResponse responseWithData:weakSelf.imageData contentType:@"image/jpeg"];
completionBlock(response);
}];
[self.davServer start];
友情链接: