user520300
user520300

Reputation: 1527

incompatible pointer type nsurl to nsstring

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 *'

at videoURL with the NSData line?

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

Upvotes: 0

Views: 7096

Answers (3)

Dileep
Dileep

Reputation: 2425

videoURL is of NSURL type

NSURL *videoURL = _movieURL;

So instead of

NSData *videoData = [NSData dataWithContentsOfFile: videoURL];

try the below code as you have URL instead of string

NSData *videoData = [NSData dataWithContentsOfURL: videoURL];

Upvotes: 8

Praksha
Praksha

Reputation: 265

Try this.... use NSMutableData instead of 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];

Upvotes: 0

Rajesh Loganathan
Rajesh Loganathan

Reputation: 11217

Try this line inside imagePickerController to save video

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);
    }
}
}

Upvotes: 0

Related Questions