writeToFile没有正确保存数据

时间:2014-12-19 03:48:52

标签: objective-c file metadata nsdata

我有来自网址(.m4a)的数据,我正在尝试保存文件,以便我可以编辑它的元数据(更改背景图片)。下面的代码似乎不起作用,我不知道为什么。它正在保存文件,但该文件为空。

_previewData = [NSMutableData dataWithContentsOfURL:[NSURL URLWithString:@"http://a281.phobos.apple.com/us/r1000/119/Music/v4/f1/7b/d6/f17bd6e3-55c0-b7e0-9863-bc522900e950/mzaf_5153970109972844579.aac.m4a"]];
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
                NSString *documentDirectory=[paths objectAtIndex:0];
                NSString *path = [documentDirectory stringByAppendingPathComponent:[NSString stringWithFormat: @"file.mp4"]];
                NSFileManager *filemanager;
                filemanager = [NSFileManager defaultManager];
                [_previewData writeToFile:path atomically:YES];
                if ([filemanager fileExistsAtPath:path]) {
                    // Runs
                    NSLog(@"It worked");
                }
                NSLog(@"%@",path);

ANMovie* file = [[ANMovie alloc] initWithFile:path]; // or .mp4
                NSData* jpegCover = UIImageJPEGRepresentation(artworkImage, 1.0);
                _imageView.image = [UIImage imageWithData:jpegCover];
                ANMetadata* metadata = [[ANMetadata alloc] init];
                metadata.albumCover = [[ANMetadataImage alloc] initWithImageData:jpegCover type:ANMetadataImageTypeJPG];
                [file setMovieMetadata:metadata];
                [file close];

                    _previewData = [NSMutableData dataWithContentsOfFile:path];

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
                NSDictionary *imageItem=@{@"public.mpeg-4-audio":self.previewData};
                NSDictionary *textItem=@{@"public.plain-text":self.linkData};

                pasteboard.items=@[imageItem,textItem];

0 个答案:

没有答案