【问题标题】:Overreleased MPMoviePlayerController under ARC in iOS SDK 8.4 on iPadiPad 上 iOS SDK 8.4 中 ARC 下过度发布的 MPMoviePlayerController
【发布时间】:2015-09-20 04:29:46
【问题描述】:

从较大项目的一部分创建了一个非常简单(单一视图)的示例项目。 它适用于 iOS SDK 8.3。

当您点击“显示”按钮时,会出现一段视频(作为模态),2 秒后,它会消失。看起来不错。但片刻之后,应用程序崩溃了,因为 -dealloc 消息被发送到一个已经释放的对象。

[MPAVController 释放]:消息发送到释放的实例

这是我的示例项目(不要忘记 Video.mp4):

ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController


@end

ViewController.m

#import "ViewController.h"

#import "MediaViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button setTitle:@"Show me!" forState:UIControlStateNormal];
    button.frame = CGRectMake(10.0, 10.0, 100.0, 30.0);
    [button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}

- (void)buttonTapped:(id)sender
{
    MediaViewController *mediaVC = [[MediaViewController alloc] initWithNibName:nil bundle:nil];
    [self presentViewController:mediaVC animated:YES completion:^{
        [self performSelector:@selector(dismissPresentedController) withObject:nil afterDelay:2.0];
    }];
}

- (void)dismissPresentedController
{
    [self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
}

@end

MediaViewController.h

#import <UIKit/UIKit.h>

@interface MediaViewController : UIViewController

@end

MediaViewController.m

#import "MediaViewController.h"

#import <MediaPlayer/MediaPlayer.h>

@interface MediaViewController ()

@property (nonatomic) MPMoviePlayerController *movieController;

@end

@implementation MediaViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    MPMoviePlayerController *movieController = [[MPMoviePlayerController alloc] initWithContentURL:[[NSBundle mainBundle] URLForResource:@"Video" withExtension:@"mp4"]];
    movieController.repeatMode = MPMovieRepeatModeOne;
    movieController.controlStyle = MPMovieControlStyleNone;
    movieController.scalingMode = MPMovieScalingModeAspectFill;
    [movieController prepareToPlay];
    self.movieController = movieController;

    UIView *movieView = movieController.view;
    movieView.frame = CGRectZero;
    movieView.translatesAutoresizingMaskIntoConstraints = NO;

    [self.view insertSubview:movieView atIndex:0];

    // Autolayout

    NSDictionary *layoutNeededViews = NSDictionaryOfVariableBindings(movieView);

    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[movieView]|"
                                                                      options:0
                                                                      metrics:nil
                                                                        views:layoutNeededViews]];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[movieView]|"
                                                                      options:0
                                                                      metrics:nil
                                                                        views:layoutNeededViews]];
}

@end

如果我关闭 ARC,错误仍然存​​在(为 MediaViewController.m 添加 -fno-objc-arc 标志并添加此行

[movieController release];

在属性分配之后。

还检查了仪器:

iPad 上经常出现此问题,但在 iPhone 上似乎不是问题。

有人遇到过这个问题吗?

(可能是一个解决方案:下载 iOS 8.3 SDK 并使用它进行存档)

干杯,

亚当

【问题讨论】:

  • 在我重新下载 Xcode 6.3.2(使用 iOS SDK 8.3)并从 ~/Downloads/... 运行后,我仍然遇到了崩溃。 Xcode 6.4 被压缩(并且源代码被删除)后,6.3.2 移动到它的位置(/Applications/)它工作正常。
  • 我在 8.4 中也看到了这个问题。即使使用从 xcode 6.3 构建的档案。我在 ios-9.0 beta 中看到了同样的问题。
  • 您是否打开了有关此问题的雷达?

标签: ios ipad sdk automatic-ref-counting mpmovieplayercontroller


【解决方案1】:

我的应用在 ios8.3 上运行良好,但在 8.4 上显示此过度发布问题。在阅读您的问题之前,我以为我已经破坏了某些东西,我在 ios8.3 上尝试了该应用

【讨论】:

  • 一直在测试这个。我似乎在模拟器上遇到了问题,但不是运行 8.4 的 iPad
  • 我可以确认 - 但我确信我也在设备上尝试过 - 它不会在我的 iPad mini (iOS 8.4) 上崩溃。仍然不确定使用此 SDK 是否可以“安全发布”...
  • 提高了雷达:21701131
  • @Jmf:请将您的雷达交叉发布到Open Radar,以便其他人更容易上当。
  • 我也面临问题,似乎谁都在使用 presentMoviePlayerViewControllerAnimated 来显示全屏视频在 8.4 中存在问题,但如果您将电影播放器​​添加为子视图,它工作正常。我也遇到了同样的问题并试图解决它。在这里查看我的帖子stackoverflow.com/questions/31311636/…
【解决方案2】:

嗯..也许我已经解决了这个问题,试试吧(它已经对我有用 - 做了很多测试)

试试这个: 在您的 MediaViewController 添加/覆盖 viewDidDisappear 方法上,如下所示:

   func viewDidDisappear(animated: Bool) {
        super.viewDidDisappear(animated)

        //just a small fix for error on iPad iOS8.4
        self.movieController.stop()
    }

如果它不起作用,请将它也添加到 viewWillDisappear - 对我有用。

【讨论】:

  • 谢谢。知道为什么它被过度发布了吗?
  • 在释放视图控制器时出了点问题……所以无论如何它都是一个错误……
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-09-18
  • 2015-10-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-04
相关资源
最近更新 更多