PresentModalViewController is not working

I am having a strange problem trying to present MPMediaPickerController using currentModalViewController. I worked fine, but lately (maybe since 3.1, I don’t remember exactly how the last time it worked) MPMediaPickerController just refuses to show itself. The screen just stays black and nothing happens except the status bar at the top, and I am forced to exit the application.

Here is my code:

// Show the music picker, allowing the user to create a playlist
- (void) showMusicPicker;
{
  [[Director sharedDirector] pause];
  [[Director sharedDirector] detach];

  musicView = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
  [window addSubview:musicView];

  musicController = [[UIViewController alloc] init];
  [musicController setView:musicView]; 
  [musicController setModalTransitionStyle: UIModalTransitionStyleCoverVertical];

  MPMediaPickerController *picker =
  [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];

  picker.delegate      = self;
  picker.allowsPickingMultipleItems = YES;
  picker.prompt      = @"Select songs to play";

  // The media item picker uses the default UI style, so it needs a default-style
  // status bar to match it visually
  [[UIApplication sharedApplication] setStatusBarHidden:NO animated: YES];

  [musicController presentModalViewController: picker animated: YES];
  [picker release];

}

As you can see, it basically copied verbatim from Apple examples, with some modifications, to make it work with Cocos2D. The window variable in the code is the application window, which is saved in the init method:

// Remember the window that the director is attached in
window = [[[[Director sharedDirector] openGLView] window] retain];

... . MPMediaPickerController , . , , , .

, .

: , :

[[Director sharedDirector] pause];
[[Director sharedDirector] detach];

[window addSubview:musicView];

:

[[[Director sharedDirector] openGLView] addSubview: musicView]

... , . , iPod , 3.0, , . , , - , , , - 20 , ( .) , Cocos2D -, Director openGLView.

+3
2

, , . ( " " ) , :

- (void) showMusicPicker;
{
  [[Director sharedDirector] pause];

  musicController = [[UIViewController alloc] init];
  [musicController setView:[[Director sharedDirector] openGLView]]; 
  [musicController setModalTransitionStyle: UIModalTransitionStyleCoverVertical];

  MPMediaPickerController *picker =
  [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];

  picker.delegate                       = self;
  picker.allowsPickingMultipleItems = YES;
  picker.prompt                     = @"Select songs to play";

  // The media item picker uses the default UI style, so it needs a default-style
  //    status bar to match it visually
  [[UIApplication sharedApplication] setStatusBarHidden:NO animated: YES];

  [musicController presentModalViewController: picker animated: YES];
  [picker release];

}

, .

+3

.

.

Apple ( , Apple).

, , , , .

, , -, ?

.

- (void)viewDidLoad 
{
    // If this is the first time.

    DisclaimerViewController *disclaimerViewController = [[DisclaimerViewController alloc]
                                                          initWithNibName:@"DisclaimerViewController" bundle:nil];
    disclaimerViewController.delegate = self;
    UINavigationController *myNavigationController = [[UINavigationController alloc]
                                                    initWithRootViewController:disclaimerViewController];
    [self presentModalViewController:myNavigationController animated:YES];
    [myNavigationController release];
    [disclaimerViewController release];

    [super viewDidLoad];
}

, , viewDidLoad? , ...

: ( , )

#pragma mark DisclaimerViewDelegate method
- (void)disclaimerControllerFinished:(DisclaimerViewController *)disclaimerViewController
{
    [disclaimerViewController dismissModalViewControllerAnimated:YES];
}

, . Apple, , - , .

@protocol DisclaimerViewDelegate;

@interface DisclaimerViewController : UIViewController 
{
    id<DisclaimerViewDelegate> delegate;
}
@property (assign) id<DisclaimerViewDelegate> delegate;

@end

@protocol DisclaimerViewDelegate <NSObject>

- (void)disclaimerControllerFinished:(DisclaimerViewController *)disclaimerViewController;
0

Source: https://habr.com/ru/post/1718110/


All Articles