How to open link in safari browser using Swift 4.2 and xcode 10.1 macos app extension

422 views Asked by At

I am developing mac os app extension in Swift 4.2 using Xcode version 10.1. Currently I am showing one popup window when user click on toolbar button.

In popup window I have loaded web page which has searchbox. Currently when user search using searchbox, result is showing in same webview (open in popup window itself)

I want to open that searchlink/result in safari browser.

Refer code

import SafariServices
import WebKit
import os.log

class SafariExtensionViewController:  SFSafariExtensionViewController, WKNavigationDelegate, WKUIDelegate{

    static let shared = SafariExtensionViewController()

    var webView : WKWebView!

    override func viewDidLoad() {
        super.viewDidLoad()

        self.preferredContentSize = NSMakeSize(380, 350) //370, 340
        webView = WKWebView(frame: self.view.frame)
        self.view.addSubview(webView)

        webView.navigationDelegate = self
        webView.translatesAutoresizingMaskIntoConstraints = false;

        let height = NSLayoutConstraint(item: webView, attribute: .height, relatedBy: .equal, toItem: self.view, attribute: .height, multiplier: 1, constant: 0)
        let width = NSLayoutConstraint(item: webView, attribute: .width, relatedBy: .equal, toItem: self.view, attribute: .width, multiplier: 1, constant: 0)
        self.view.addConstraints([height,width])

        let startingUrl = URL(string: mySiteURL);
        webView.load(URLRequest(url: startingUrl!));
    }
}

How can I open link in safari browser tab instead of popup window?

Also, does UIKit is supported with xcode 10.1 and Swift 4.2?

Does UIKit works for mac OS App?

0

There are 0 answers