Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overreleased MPMoviePlayerController under ARC in iOS SDK 8.4 on iPad

Created a very simple (single view) sample project from a part of a bigger one. It worked with the iOS SDK 8.3.

When you hit the "Show me" button, a video comes up (as modal) and 2 secs later, it disappears. Looks good. But few moments later the app crashes because a -dealloc message is sent to an already deallocated object.

[MPAVController release]: message sent to deallocated instance

Here's my sample project (don't forget about the 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

If I turn off the ARC, the bug is still alive (adding -fno-objc-arc flag for the MediaViewController.m and adding this line

[movieController release];

after the property assign.

Also checked with Instruments: Instruments check for Zombie objects

The issue occurs on iPad (all the time) but it seems not a problem on iPhone.

Has anyone faced this issue?

(Probably a solution: download the iOS 8.3 SDK and make archive with that)

Cheers,

Adam

like image 795
Adam Szabo Avatar asked Jul 02 '15 14:07

Adam Szabo


People also ask

What is iOS SDK?

The iOS software development kit (iOS SDK) is a collection of tools for the creation of apps for Apple's mobile operating system.

Is iOS SDK free?

The iOS SDK is a free download for Mac users. It is not available for Microsoft Windows personal computers. To test the application, get technical support, and distribute applications through App Store, developers are required to subscribe to the Apple Developer Program.


2 Answers

Hmm.. maybe I got a fix for that, just try it (it already works for me - did many tests)

Try this: On your MediaViewController add/override viewDidDisappear method like this:

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

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

If it don't works add it also in viewWillDisappear - worked for me.

like image 187
kurtanamo Avatar answered Dec 10 '22 17:12

kurtanamo


My app works fine on ios8.3, but is showing this over-release issue on 8.4. I'd assumed I'd broken something until having read your question I tried the app on ios8.3

like image 35
Jmf Avatar answered Dec 10 '22 15:12

Jmf