Skip to content

Commit

Permalink
Merge pull request sahin#108 from mobileplayer/fix/showContentActions
Browse files Browse the repository at this point in the history
[MobilePlayer] Fix showContentActions crash on iPads
  • Loading branch information
isair committed Dec 11, 2015
2 parents 84c5feb + 76fb5b5 commit eed455e
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions MobilePlayer/MobilePlayerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public class MobilePlayerViewController: MPMoviePlayerViewController {

private func initializeControlsView() {
(getViewForElementWithIdentifier("playback") as? Slider)?.delegate = self

(getViewForElementWithIdentifier("close") as? Button)?.addCallback(
{
if let navigationController = self.navigationController {
Expand All @@ -173,15 +174,22 @@ public class MobilePlayerViewController: MPMoviePlayerViewController {
}
},
forControlEvents: .TouchUpInside)
(getViewForElementWithIdentifier("action") as? Button)?.addCallback(
showContentActions,
forControlEvents: .TouchUpInside)

if let actionButton = getViewForElementWithIdentifier("action") as? Button {
actionButton.addCallback(
{
self.showContentActions(actionButton)
},
forControlEvents: .TouchUpInside)
}

(getViewForElementWithIdentifier("play") as? ToggleButton)?.addCallback(
{
self.resetHideControlsTimer()
self.state == .Playing ? self.pause() : self.play()
},
forControlEvents: .TouchUpInside)

initializeControlsViewTapRecognizers()
}

Expand Down Expand Up @@ -336,8 +344,11 @@ public class MobilePlayerViewController: MPMoviePlayerViewController {
/// `UIActivityViewController` with `activityItems` set as its activity items. If content is playing, it is paused
/// automatically at presentation and will continue after the controller is dismissed. Overriding this method is
/// recommended if you want to change this behavior.
public func showContentActions() {
// FIXME: iPad crash on iOS 8+
///
/// parameters:
/// - sourceView: On iPads the activity view controller is presented as a popover and a source view needs to
/// provided or a crash will occur.
public func showContentActions(sourceView: UIView? = nil) {
guard let activityItems = activityItems else { return }
let wasPlaying = (state == .Playing)
moviePlayer.pause()
Expand All @@ -353,6 +364,12 @@ public class MobilePlayerViewController: MPMoviePlayerViewController {
self.moviePlayer.play()
}
}
if let sourceView = sourceView {
activityVC.popoverPresentationController?.sourceView = controlsView
activityVC.popoverPresentationController?.sourceRect = sourceView.convertRect(
sourceView.bounds,
toView: controlsView)
}
presentViewController(activityVC, animated: true, completion: nil)
}

Expand Down

0 comments on commit eed455e

Please sign in to comment.