@coltonboyd or
import ui
from objc_util import *
import os
#========= SFSafariViewController to allow Safari extension in WebView
def safariViewControllerDidFinish_(_self, _cmd, _controller):
#print('SafariViewControllerDidFinish_')
SFSafariViewController = ObjCInstance(_controller)
#....... still close view problems
try:
SFSafariViewController.uiview.close()
except Exception as e:
SFSafariViewController.uiview().close()
methods = [safariViewControllerDidFinish_,]
protocols = ['SFSafariViewControllerDelegate']
try:
MySFSafariViewControllerDelegate = ObjCClass('MySFSafariViewControllerDelegate')
except:
MySFSafariViewControllerDelegate = create_objc_class('MySFSafariViewControllerDelegate', methods=methods, protocols=protocols)
@on_main_thread
def MySFSafariViewController(url, w=None, h=None, local=None, popover_location=None, reader=False):
uiview = ui.View()
uiview.background_color = 'white'
if w and h:
uiview.frame = (0,0,w,h)
uiview.present('sheet',hide_title_bar=True)
else:
uiview.present('fullscreen',hide_title_bar=True)
# SFSafariViewController only accepts http: or https:, not file:
# thus, in this case, we need to create a local server
ns_url = nsurl(url)
SFSafariViewControllerConfiguration = ObjCClass('SFSafariViewControllerConfiguration').alloc().init()
#
SFSafariViewControllerConfiguration.setEntersReaderIfAvailable_(reader)
SFSafariViewController = ObjCClass('SFSafariViewController').alloc().initWithURL_configuration_(ns_url,SFSafariViewControllerConfiguration)
#print(dir(SFSafariViewController))
# Use new delegate class:
delegate = MySFSafariViewControllerDelegate.alloc().init()
SFSafariViewController.delegate = delegate
SFSafariViewController.setModalPresentationStyle_(3)
SFSafariViewController.uiview = uiview # used by delegate
objc_uiview = ObjCInstance(uiview)
SUIViewController = ObjCClass('SUIViewController')
vc = SUIViewController.viewControllerForView_(objc_uiview)
vc.presentViewController_animated_completion_(SFSafariViewController, True, None)
if __name__ == '__main__':
url = 'https://www.eqsl.cc/qslcard/Index.cfm'
url = 'http://www.kanisette.com/2018/06/roule-au-saumon-et-courgettes.html'
MySFSafariViewController(url,600,500)