0
我想弄清楚如何更新我的UIProgressView
,而我上傳視頻到我的服務器。視頻是用戶挑選視頻,在這裏是我的代碼上傳到我的服務器:更新UIProgressView,同時發佈視頻到php
NSMutableArray *array = [[NSMutableArray alloc]initWithContentsOfFile:[self saveUserLogin]];
int test;
NSString *string = [array objectAtIndex:3];
test = [string intValue];
test++;
NSData *videoData = fileData;
NSString *urlString = [[NSString alloc]initWithFormat:@"http://www.site.com/members/uploadMovie.php?&username=%@", [array objectAtIndex:0]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[request addValue:contentType forHTTPHeaderField:@"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
NSString *postName = [[NSString alloc]initWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"vid%i.mov\"\r\n", test];
[body appendData:[[NSString stringWithString:postName] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:videoData]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"%@", returnString);
NSArray *values = [[NSArray alloc] initWithObjects: [array objectAtIndex:0],[array objectAtIndex:1], [array objectAtIndex:2], [NSString stringWithFormat:@"%i", test], nil];
[values writeToFile:[self saveUserLogin] atomically:YES];
[self.delegate didFinishController:self];
我UIProgressView
被命名爲ProgressForUpload
,我猜,我將不得不使用一個新的線程。這個程序我也做上傳圖片,我能夠通過這樣來更新的圖像:
int copy = ForProgress;
ForProgress = 100/ForProgress;
NSString *togetridof = [[NSString alloc]initWithFormat:@"%f", ForProgress];
NSString *stringWithoutdot = [togetridof stringByReplacingOccurrencesOfString:@"." withString:@""];
if(copy > 1 && copy < 11){
progressString = [[NSString alloc]initWithFormat:@"0.%@", stringWithoutdot];
}
if (copy > 10) {
progressString = [[NSString alloc]initWithFormat:@"0.0%@", stringWithoutdot];
}
if(ForProgress == 100){
progressString = [[NSString alloc]initWithFormat:@"%@", stringWithoutdot];
}
tellprogress = [progressString floatValue];
然後當我上傳我創建一個新的線程,將增加告訴進步到目前的進展圖像,直到完成。
我不知道這樣的東西是否適用於上傳視頻。
謝謝,雅各布
我能舉個例子嗎? – Jacob
http://www.iphonedevsdk.com/forum/iphone-sdk-development/14919-how-upload-download-http-server-2.html有一些。我已經在應用程序中非正式上傳,但我不重寫該委託方法,因爲我的應用程序不關心進度。 (大多數請求很小。) – Norman
另一個:http://mscerts.programming4.us/programming/iphone%20programming%20%20%20connecting%20to%20the%20network%20-%20getting%20data%20from%20the% 20internet.aspx – Norman