由于需要实现把本地文件上传到IOS设备的功能,在网上搜了一下,发现了CocoaWebResource这个开源项目,https://github.com/robin/cocoa-web-resource
它的demo就是一个简单的文件服务器了。
不过这个demo里没有实现上传进度的显示。我就浏览了一下源代码,发现在HTTPServer.h的头部定义了
#define HTTPUploadingStartNotification @"UploadingStarted"
#define HTTPUploadingProgressNotification @"UploadingProgress"
#define HTTPUploadingFinishedNotification @"UploadingFinished"
#define HTTPFileDeletedNotification @"FileDeleted"
然后在HTTPConnection.m的handleMultipartHeader函数中调用了
[[NSNotificationCenter defaultCenter] postNotificationName:HTTPUploadingStartNotification object:filename];
[[NSNotificationCenter defaultCenter] postNotificationName:HTTPUploadingProgressNotification object:progress];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(uploadingStart:) name:@"UploadingStarted" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(uploadingProgress:) name:@"UploadingProgress" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(uploadingFinish:) name:@"UploadingFinished" object:nil];
然后实现uploadingStart, uploadingProgress,uploadingFinish的功能//开始上传
-(void)uploadingStart:(NSNotification *)notification
{
}
//正在上传
-(void)uploadingProgress:(NSNotification *)notification
{
}
//上传完成
-(void)uploadingFinish:(NSNotification *)notification
{
}
不过没发现HTTPConnection.m中有添加HTTPUploadingFinishedNotification上传完成的进度消息提示if ([progress floatValue] == 1.0) {
[[NSNotificationCenter defaultCenter] postNotificationName:HTTPUploadingFinishedNotification object:nil];
}