SGWiFiUpload is a tool based on CocoaHTTPServer for iOS to upload files through WiFi. By using this framework, you can upload files easily. It can be used for many locations, such as photos and videos upload.Files will save to Caches by default.
- Download SGWiFiUpload and try out the included iPhone example app.
Drag the SGWiFiUpload
folder to your project.
#import "SGWiFiUploadManager.h"
- (void)setupServer {
SGWiFiUploadManager *mgr = [SGWiFiUploadManager sharedManager];
BOOL success = [mgr startHTTPServerAtPort:10086];
if (success) {
NSLog(@"URL = %@:%@",mgr.ip,@(mgr.port));
}
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fileUploadStart:) name:SGFileUploadDidStartNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fileUploadFinish:) name:SGFileUploadDidEndNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fileUploadProgress:) name:SGFileUploadProgressNotification object:nil];
}
#pragma mark Notification Callback
- (void)fileUploadStart:(NSNotification *)nof {
NSString *fileName = nof.object[@"fileName"];
NSLog(@"Start Upload <%@>",fileName);
}
- (void)fileUploadFinish:(NSNotification *)nof {
NSLog(@"File Upload Finished.");
}
- (void)fileUploadProgress:(NSNotification *)nof {
CGFloat progress = [nof.object[@"progress"] doubleValue];
NSLog(@"%.2f",progress);
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
You can use the default WiFi Page to tell users how and where to use it.
```objective-c [[SGWiFiUploadManager sharedManager] showWiFiPageFrontViewController:self]; ```You can change the file save location by change the value of savePath
in SGWiFiUploadManager
.
You can change the file save location by change the value of webRoot
in SGWiFiUploadManager
, the server will search index.html
and upload.html
in this path.
You can change the count of files to upload by modify the index.html
in Web
Folder.
You can add input
tag with type="file"
in the form
whose action is upload.html
and method is POST
.