iPhone 上的录像机

发布于 2024-12-02 07:46:50 字数 1343 浏览 1 评论 0原文

这是我制作的程序。 但我跑得不好。当我在 iPhone 上打开这个程序时,它立即关闭。 我将展示我的代码并回答我有什么问题。

UIImagePickerController * videoRecorder = [[[UIImagePickerController alloc] init] autorelease];
    videoRecorder.delegate = self;
    videoRecorder.sourceType = UIImagePickerControllerSourceTypeCamera;
    NSArray *sourceTypes = [UIImagePickerController availableMediaTypesForSourceType:videoRecorder.sourceType];
    if (![sourceTypes containsObject:(NSString*)kUTTypeMovie] ) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil 
                                                        message:@"Device Not Supported for video Recording."     
                                              cancelButtonTitle:@"Yes"
                                              otherButtonTitles:@"No",nil];
        [alert show];
        [alert release];
        return;
    }
    videoRecorder.sourceType = UIImagePickerControllerSourceTypeCamera;
    videoRecorder.mediaTypes = [NSArray arrayWithObject:(NSString*)kUTTypeMovie];           
    videoRecorder.videoQuality = UIImagePickerControllerQualityTypeLow;
    videoRecorder.videoMaximumDuration = 120;
    videoRecorder.delegate = self;
    self.recorder_ = videoRecorder;                 
    [videoRecorder release];
    [self presentModalViewController:self.recorder_ animated:YES]; 

This is the program that i make.
But i doesn't run good. when i open this program on iphone it immediatly turn off.
I will show my code and answer me what is the problem.

UIImagePickerController * videoRecorder = [[[UIImagePickerController alloc] init] autorelease];
    videoRecorder.delegate = self;
    videoRecorder.sourceType = UIImagePickerControllerSourceTypeCamera;
    NSArray *sourceTypes = [UIImagePickerController availableMediaTypesForSourceType:videoRecorder.sourceType];
    if (![sourceTypes containsObject:(NSString*)kUTTypeMovie] ) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil 
                                                        message:@"Device Not Supported for video Recording."     
                                              cancelButtonTitle:@"Yes"
                                              otherButtonTitles:@"No",nil];
        [alert show];
        [alert release];
        return;
    }
    videoRecorder.sourceType = UIImagePickerControllerSourceTypeCamera;
    videoRecorder.mediaTypes = [NSArray arrayWithObject:(NSString*)kUTTypeMovie];           
    videoRecorder.videoQuality = UIImagePickerControllerQualityTypeLow;
    videoRecorder.videoMaximumDuration = 120;
    videoRecorder.delegate = self;
    self.recorder_ = videoRecorder;                 
    [videoRecorder release];
    [self presentModalViewController:self.recorder_ animated:YES]; 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

末が日狂欢 2024-12-09 07:46:50

第一:以后请使用代码格式化程序。这看着就心疼。

第二:您双重释放 UIImagePicketController (videoRecorder) 自动释放将在当前运行循环退出后释放它,但您也在此处的方法调用接近结束时显式释放它,因此当 iOS 清理自动释放池时,它将获得双重释放并崩溃。

由于格式问题,我无法很好地阅读其余部分,但这似乎是您最有可能确定导致崩溃的原因。

First: Use the code formatter in the future please. This hurts to look at.

Second: You're double releasing UIImagePicketController (videoRecorder) auto-release will release it after the current runloop exits, but you're also explicitly releasing it near the end of your method call here, so when iOS cleans up the auto-release pool, it will get a double release and crash.

I can't read the rest of this well due to the formatting, but that seems like your most likely bet for what's causing the crash.

り繁华旳梦境 2024-12-09 07:46:50

您应该编辑您的帖子并使代码可读。

问题是您在第一行中自动释放 videoRecorder,因此您不必调用 -release。 videoRecorder 在第一行中的保留计数为零,当您将其分配给 self.recorder_ 时,保留计数为 1。当您调用释放时,保留计数将变为零,并且自动释放池会使对象在记录器呈现为模态视图控制器之前消失。删除那个 -release 调用,你应该没问题。此外,您的代码将 delegate 和 sourceType 设置两次。

You should edit your post and make the code readable.

The problem is that you autorelease videoRecorder in the first line so you don't have to call the -release. videoRecorder has a retain count of zero in the first line and a retain count of one when you assign it to self.recorder_. When you call the release, then retain count goes to zero and the autorelease pool makes the object go away before the recorder can be presented as a modal view controller. Remove that -release call and you should be fine. Also, your code sets the delegate and sourceType two times.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文