gpt4 book ai didi

iphone - 将视频发布到 php 时更新 UIProgressView

转载 作者:行者123 更新时间:2023-11-29 04:55:41 29 4
gpt4 key购买 nike

我正在尝试弄清楚如何在将视频上传到服务器时更新我的​​ UIProgressView。该视频是用户选择的视频,这是我上传到我的服务器的代码:

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,我猜我必须使用一个新线程。我正在制作的这个应用程序还上传图像,我可以通过执行以下操作来更新图像的 progressview:

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];

然后,当我上传图像时,我创建一个新线程,它将告诉进度添加到当前进度上,直到完成。

我不知道这样的事情是否适用于上传视频。

谢谢,雅各布

最佳答案

我会使用异步网络来实现此目的,然后您可以从您的

- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response;

Apple 继续警告主线程上的网络状况不佳。

关于iphone - 将视频发布到 php 时更新 UIProgressView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8032402/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com