iOS上的CocoaHTTPServer:设置服务器,以便用户可以下载NSData作为文件

bri*_*dir 6 download hyperlink nsdata cocoahttpserver ios

我想使用以下网页CocoaHTTPServer:应该有一个下载文件的链接,但源文件必须是NSData内存中的对象.

就我在样本中看到的,有一种简单的方法可以将iPhone上的某些文件链接到超链接.可以"链接" NSData吗?

非常感谢你的例子.

mih*_*iho 7

您需要做的就是返回HTTPDataResponseHTTPConnection子类.

如果你想要一个例子来看看被称为CocoaHTTPServer样品DynamicServer和替换- httpResponseForMethod: URI:MyHTTPConnection类似下面的内容:

- (NSObject<HTTPResponse> *)httpResponseForMethod:(NSString *)method URI:(NSString *)path
{
    // Before returning you can analyze the passed path argument and select the correct data object to return...
    return [[HTTPDataResponse alloc] initWithData:placeYourDataInstanceHere];
}
Run Code Online (Sandbox Code Playgroud)