1
1

【Swift】アプリ内でSafariを起動する(SFSafariViewController)

Last updated at Posted at 2023-03-02

アプリ内で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)を触った時の共有アイテムも指定できそうです。

公式ドキュメント

SFSafariViewController

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1