Skip to content

Instantly share code, notes, and snippets.

Avatar

Dragos Dobrean dobreandl

View GitHub Profile
View InitWebView.swift
private func configureWebView() {
let wkWebConfig = WKWebViewConfiguration() // We create a web view configuration
let wkUserController = WKUserContentController() // We create a user content controller for adding the JS for manipulating the CSS of the web page
wkWebConfig.userContentController = wkUserController
addHideHeaderScript(wkWebController: wkUserController) // We add the the hide header script
// We configure the web view, and add it as a subview to the current view
webView = WKWebView(frame: self.view.bounds, configuration: wkWebConfig)
View AddJSToWebView.swift
private func addPageHasChangedDelegateScript(wkWebController: WKUserContentController) {
// load the script from the file and create a WKUserScript object
let scriptURL = Bundle.main.path(forResource: Constants.detectPageChangeScript, ofType: "js")
let scriptContent = try! String.init(contentsOfFile: scriptURL!)
let script = WKUserScript(source: scriptContent, injectionTime: .atDocumentStart, forMainFrameOnly: false)
// Add the script to the WKUserContentController
wkWebController.addUserScript(script)
// Register for receiving callbacks from javascript for a notification name
View JSWebViewDelegate.swift
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
if (message.name == “notification_name”) {
print("Page changed")
}
}
View ChangeRootViewController.swift
let startupViewController = StartupViewController()
let navController = UINavigationController(rootViewController: startupViewController)
appDelegate.window.rootViewController = navController
View ChangeRootViewControllerWithWindow.swift
let newWindow = UIWindow(frame: UIScreen.main.bounds)
newWindow.rootViewController = rootViewController
UIWindow.transition(with: appDelegate.window, duration: 0.3, options: .transitionCrossDissolve, animations: {
let oldWindow = appDelegate.window
appDelegate.window = newWindow
newWindow.makeKeyAndVisible()
oldWindow?.rootViewController?.dismiss(animated: false, completion: nil)
View xcodebuild-list.sh
xcodebuild -list -project <your_project_name>.xcodeproj
View xcodebuild-build-test
xcodebuild -workspace <your_project_name>.xcworkspace -scheme <your_desired_schema> -configuration <your_desired_configuration> -destination 'platform=iOS Simulator,name=iPad Pro (12.9-inch),OS=10.2' -derivedDataPath <derived_data_path> BUILD_DIR=<build_directory_path> -UseModernBuildSystem=YES clean build -enableCodeCoverage=YES test
View xcodebuild-and-test
xcodebuild -workspace <your_project_name>.xcworkspace \
-scheme <your_desired_schema> -configuration <your_desired_configuration> \
-destination 'platform=iOS Simulator,name=iPad Pro (12.9-inch),OS=10.2' \
-derivedDataPath <derived_data_path> BUILD_DIR=<build_directory_path> \
-UseModernBuildSystem=YES clean build -enableCodeCoverage=YES test
You can’t perform that action at this time.