1

当我编写下面提到的代码时出现此错误。基本上我想将 UIImagePickerController 捕获的视频保存到我的应用程序目录。我没有得到我犯错的地方。请帮助我..

- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info
{
    NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
    [self dismissModalViewControllerAnimated:NO];
    // Handle a movie capture
    if (CFStringCompare ((__bridge_retained CFStringRef) mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo)
    {
        NSArray  *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDir  = [documentPaths objectAtIndex:0];
        NSString *movieName = [NSString stringWithFormat:@"%@.mov",[self getNameForVideo]];
        NSString *moviePath    = [documentsDir stringByAppendingPathComponent:movieName];
        NSURL * movieURL = [info valueForKey:UIImagePickerControllerMediaURL];
        NSData * movieData = [NSData dataWithContentsOfURL:movieURL];
        if([movieData writeToFile:moviePath atomically:NO])
        {
            [self saveVideoInfoInDatabase];
        }
        else
        {
            NSLog(@"Video could not be saved to the document directry");
        }
    }
}
4

1 回答 1

1

这是内存限制的原因(以各种方式表现出来)。这也可能是下载完成和当时的 UI 之间的线程交互行为的原因。有人指出,当后者在前者之前创建时,显示 UIAlertView 和创建 UIWebView 存在问题。如果您有一个快速下载连接(在模拟器和本地 Web 服务器中很可能是这种情况),那么您可能会发现下载完成太快以至于 UI 无法准备好显示通知下载完成

于 2012-09-26T11:06:45.843 回答