アプリ内でSafariを起動する方法
環境
macOS Monterey バージョン 12.6.3
Xcode バージョン 14.2
コード
ViewController.swift
import SafariServices
SafariServicesを忘れずに
ViewController.swift
func openSafari() {
let url = URL(string: "https://qiita.com/")
if let url = url {
let vc = SFSafariViewController(url: url)
self.present(vc, animated: true, completion: nil)
}
}
Delegate
SFSafariViewControllerDelegate
があります。
ユーザーがSafari内の共有ボタン(Action button)を触った時の共有アイテムも指定できそうです。