不兼容的指针类型nsurl到nsstring

时间:2022-02-21 00:14:39

I'm capturing a video clip but I'm trying to save the file to the app documents dir. I'm getting the following

我正在捕捉视频剪辑,但我正在尝试将文件保存到应用程序文档目录。我得到以下内容

Incompatible pointer types sending 'NSURL' to parameter of type 'NSString *'

不兼容的指针类型将'NSURL'发送到'NSString *'类型的参数

at videoURL with the NSData line?

在带有NSData线的videoURL?

int timestamp = [[NSDate date] timeIntervalSince1970];
NSURL *videoURL = _movieURL;
NSData *videoData = [NSData dataWithContentsOfFile: videoURL];

NSString *videoString = [NSString stringWithFormat:@"%d.MOV", timestamp];
NSString *videoPath = [documentsPath stringByAppendingPathComponent: videoString]; //Add the file name

[videoData writeToFile:videoPath atomically:NO];


-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    self.movieURL = info[UIImagePickerControllerMediaURL];
    // NSLOg("MOVIE URL: %@", _movieURL);
    [picker dismissViewControllerAnimated:YES completion:NULL];
}

3 个解决方案

#1


6  

videoURL is of NSURL type

videoURL是NSURL类型

NSURL *videoURL = _movieURL;

So instead of

而不是

NSData *videoData = [NSData dataWithContentsOfFile: videoURL];

try the below code as you have URL instead of string

尝试下面的代码,因为你有URL而不是字符串

NSData *videoData = [NSData dataWithContentsOfURL: videoURL];

#2


0  

Try this line inside imagePickerController to save video

在imagePickerController中尝试此行以保存视频

UISaveVideoAtPathToSavedPhotosAlbum (
                    moviePath, nil, nil, nil);

Code:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info; {
  // Handle a movie capture
if (CFStringCompare ((CFStringRef) mediaType, kUTTypeMovie, 0)
        == kCFCompareEqualTo) {

    NSString *moviePath = [[info objectForKey:
                UIImagePickerControllerMediaURL] path];

    if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
        UISaveVideoAtPathToSavedPhotosAlbum (
                moviePath, nil, nil, nil);
    }
}
}

#3


0  

Try this.... use NSMutableData instead of NSData

试试这个....使用NSMutableData而不是NSData

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSDate *aDate = [NSDate date];
NSTimeInterval interval = [aDate timeIntervalSince1970];
NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%d.mov",(int)interval]];
[vidData writeToFile:localFilePath atomically:YES];

#1


6  

videoURL is of NSURL type

videoURL是NSURL类型

NSURL *videoURL = _movieURL;

So instead of

而不是

NSData *videoData = [NSData dataWithContentsOfFile: videoURL];

try the below code as you have URL instead of string

尝试下面的代码,因为你有URL而不是字符串

NSData *videoData = [NSData dataWithContentsOfURL: videoURL];

#2


0  

Try this line inside imagePickerController to save video

在imagePickerController中尝试此行以保存视频

UISaveVideoAtPathToSavedPhotosAlbum (
                    moviePath, nil, nil, nil);

Code:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info; {
  // Handle a movie capture
if (CFStringCompare ((CFStringRef) mediaType, kUTTypeMovie, 0)
        == kCFCompareEqualTo) {

    NSString *moviePath = [[info objectForKey:
                UIImagePickerControllerMediaURL] path];

    if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
        UISaveVideoAtPathToSavedPhotosAlbum (
                moviePath, nil, nil, nil);
    }
}
}

#3


0  

Try this.... use NSMutableData instead of NSData

试试这个....使用NSMutableData而不是NSData

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSDate *aDate = [NSDate date];
NSTimeInterval interval = [aDate timeIntervalSince1970];
NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%d.mov",(int)interval]];
[vidData writeToFile:localFilePath atomically:YES];