The SfSafariViewController is a poor replacemet for UIWebview, IOS 12 deprecates UIWebview so we have decided to not use it
but we are left with two possibilities .
SFSafariVeiwController
wKwebview
In experimenting we found that our DRM conent which played well in UiWebView no longer plays in WKwebView , that is a
show stopper and seems like a bad omission for Apple which is pushing WkwebView as the replacement for UIwebView.
So we are stuck with SFSafariViewController
but this webView has so many issues.
We need to implement touch gestures when azure media player goes into full screen mode, but rather than displaying in the full screen browser on the iphone selecting full screen shells out to a player.
There does not seen to be anyway to attach gestures to that AVplayerViewController instance
After some experiementation i Subclassed SFSafariViewController and created a custom toolbar at the bottom of the diiplay and placed a fullscreen button which launches AVplayerViewcontroller.
if I launch from the safariview controller , the player never appears and I get an error message that I am attempting to present a view from a veiwcontroller not in the hierachy.
If I present of of sf (safariviewcontroller) presenting view controller , the avpllayer does launch, but when I close AvPlayerViewController SFsafariviewcontroller is present again but both my custon button and the done button are disabled.
Its so frustrating because there just doesn't seem much you can do to customize this controller, UIwebView was so much better than the substitutes.
Here is my cust SafariViewController
import UIKit
import SafariServices
import Material
class SCSafariViewcontroller: SFSafariViewController {
var toolView : Toolbar!
var clearbutton : IconButton!
var fileId:String!
override func viewDidLoad() {
super.viewDidLoad()
// clearbutton.addTarget(self, action: #selector(handleClearButton), for: .touchUpInside)
// Do any additional setup after loading the view.
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
var frame = self.view.frame
let OffsetY: CGFloat = 44
frame.origin = CGPoint(x: frame.origin.x, y: frame.origin.y - OffsetY)
frame.size = CGSize(width: frame.width, height: frame.height + (1 * OffsetY))
// self.view.frame = frame
Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(SCSafariViewcontroller.drawNavBar), userInfo: nil, repeats: false)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
print("this")
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
print("i laid out my subviews")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@objc func setFullScreenPlay() {
clearbutton = IconButton(image: UIImage(named: "ic_fullscreen_36"), tintColor: UIColor.darkText)
}
@objc func drawNavBar() {
var height: CGFloat!
var y: CGFloat!
if UIDevice.current.orientation.isLandscape {
print("Landscape")
height = 44
y = self.view.frame.height - height
} else {
print("Portrait")
height = 85
y = self.view.frame.height - height
}
// It can be any overlay. May be your logo image here inside an imageView.
// let overlay = UIView(frame: CGRect(x: 0, y: y, width: self.view.frame.width, height: height))
toolView = Toolbar()
toolView.frame = CGRect(x : 0 , y : y , width : self.view.frame.width , height : height)
toolView.width = self.view.width
toolView.rightViews = [clearbutton]
toolView.titleLabel.font = RobotoFont.regular(with: 14)
// toolView.titleLabel.text = "Viewer"
toolView.titleLabel.textAlignment = .left
toolView.dividerAlignment = .top
toolView.backgroundColor = UIColor.gray
self.view.addSubview(toolView)
}
@objc
func handleClearButton() {
}
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
DispatchQueue.main.async() {
self.toolView.removeFromSuperview()
Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(SCSafariViewcontroller.drawNavBar), userInfo: nil, repeats: false)
}
}
}And here is how I am trying to present , tried with dimissing and reopening he controller and without, same issues
//vc.dismiss(animated: true, completion: {
DispatchQueue.main.async() {
pvc?.modalPresentationStyle = UIModalPresentationStyle.popover
self.vc.navigationController?.present(playerViewController, animated: true, completion: {
AssetPlaybackManager.sharedManager.setAssetForPlayback(asset)
})
}
})