我正在尝试将我的视频文件从我的应用程序上传到服务器,我在uploadfilewitherror的代码中遇到异常。
2014-08-22 15:55:49.092 [1990:907] - [__ NSCFNumber localizedDescription]:无法识别的选择器发送到实例0x1f58fd60 2014-08-22 15:55:49.096 [1990:907] *由于未捕获的异常终止应用程序' NSInvalidArgumentException',原因:' - [__ NSCFNumber localizedDescription]:无法识别的选择器发送到实例0x1f58fd60' * 第一次抛出调用堆栈: (0x326ed2a3 0x3a36b97f 0x326f0e07 0x326ef531 0x32646f68 0x74bdd 0x7328f 0x32f82d41 0x32f7a5c1 0x32ff2be3 0x3a78311f 0x3a7824b7 0x3a783dcb 0x326c0f3b 0x32633ebd 0x32633d49 0x361e62eb 0x34549301 0x6fac3 0x6fa50) libc ++ abi.dylib:terminate调用抛出异常
Code is as below.
- (void)viewDidLoad
{
[super viewDidLoad];
ftpRequest = [[SCRFTPRequest alloc] init];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
- (void) recordVideo {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
picker.videoQuality = UIImagePickerControllerQualityTypeLow;
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
picker.videoMaximumDuration = 60;
NSArray *sourceTypes =
[UIImagePickerController availableMediaTypesForSourceType:picker.sourceType];
if (![sourceTypes containsObject:(NSString *)kUTTypeMovie ]){
NSLog(@"Can't save videos");
}
[self presentModalViewController:picker animated:YES];
[picker release];
}
- (IBAction)startRecordClick:(id)sender {
[self recordVideo];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if (![mediaType isEqualToString:kUTTypeMovie])
return;
NSURL *mediaURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSString* moviePath = mediaURL.absoluteString;
NSString *tempFilePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
NSLog(@"filepath %@",tempFilePath);
//try
ftpRequest = [[SCRFTPRequest alloc] initWithURL:[NSURL URLWithString:@"ftp://"]
toUploadFile:[[NSBundle mainBundle] pathForResource:@"tempFilePath" ofType:@"MOV"]];
ftpRequest.username = @"";
ftpRequest.password = @"";
// Specify a custom upload file name (optional)
ftpRequest.customUploadFileName = @"c.MOV";
// The delegate must implement the SCRFTPRequestDelegate protocol
ftpRequest.delegate = self;
[ftpRequest startRequest];
//try
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(tempFilePath))
{
UISaveVideoAtPathToSavedPhotosAlbum (tempFilePath, nil, nil, nil);
}
[picker dismissModalViewControllerAnimated: YES];
[picker release];
}
-(void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
NSLog(@"Finished with error: %@", error);
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissModalViewControllerAnimated: YES];
[picker release];
}
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
}
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
}
- (void)ftpRequestDidFinish:(SCRFTPRequest *)request {
NSLog(@"Upload finished.");
}
- (void)ftpRequest:(SCRFTPRequest *)request didFailWithError:(NSError *)error {
NSLog(@"Upload failed: %@", [error localizedDescription]);
}
// Optional delegate methods
- (void)ftpRequestWillStart:(SCRFTPRequest *)request {
NSLog(@"Will transfer %lld bytes.", request.fileSize);
}
- (void)ftpRequest:(SCRFTPRequest *)request didWriteBytes:(NSUInteger)bytesWritten {
NSLog(@"Transferred: %d", bytesWritten);
}
- (void)ftpRequest:(SCRFTPRequest *)request didChangeStatus:(SCRFTPRequestStatus)status {
switch (status) {
case SCRFTPRequestStatusOpenNetworkConnection:
NSLog(@"Opened connection.");
break;
case SCRFTPRequestStatusReadingFromStream:
NSLog(@"Reading from stream...");
break;
case SCRFTPRequestStatusWritingToStream:
NSLog(@"Writing to stream...");
break;
case SCRFTPRequestStatusClosedNetworkConnection:
NSLog(@"Closed connection.");
break;
case SCRFTPRequestStatusError:
NSLog(@"Error occurred.");
break;
case SCRFTPRequestStatusNone:
NSLog(@"Error occurred - NONE.");
break;
}
}
@end
答案 0 :(得分:0)
提供的代码没有任何与FTP服务器相关的代码库。
当您从选择器控制器中使用/完成视频选择时, didFinishPickingMediaWithInfo
委托将触发。如果您想在没有任何按钮操作的情况下同时将视频上传到FTP,请使用以下代码。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSURL *mediaURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSData *videoData = [NSData dataWithContentsOfURL:videoURL];
//search for FTP code samples and upload this NSData to the FTP.
//save this video
NSString *moviePath = [mediaURL path];
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
UISaveVideoAtPathToSavedPhotosAlbum (moviePath, nil, nil, nil);
}
}
如果您想在按钮上执行其他操作,将视频发送到ftp服务器,请保存资产URL并使用ALAsset
Url检索视频文件,将其转换为strems并上传到FTP。