Freedom 🦅 (自由 🦅)

The Freedom to Open URLs in Third-Party Browsers on iOS with Custom UIActivity Subclasses. (使用自定义 UIActivity 子类在 iOS 上于第三方浏览器中打开 URL 的自由。)

Swift Support

CocoaPods Carthage Compatible SwiftPM Compatible


About (关于)

Freedom enables your app to open URLs in third-party browsers that your users have installed on their device. (Freedom 使你的应用能够在用户设备上已安装的第三方浏览器中打开 URL。)

Currently Supported (目前支持)

Screenshot (截图)

Installation Instructions (安装说明)

Swift Version (Swift 版本) Branch Name (分支名称) Will Continue to Receive Updates? (是否继续接收更新?)
5.1+ master (主分支) Yes (是)
5.0 swift5.0 No (否)
4.2 swift4.2 No (否)
3.2 swift4.1 No (否)
3.2 swift3.2 No (否)
3.1 swift3.1 No (否)

CocoaPods

pod 'Freedom' # Swift 5.1+
pod 'Freedom', :git => 'https://github.com/ArtSabintsev/Freedom.git', :branch => 'swift5.0' # Swift 5.0
pod 'Freedom', :git => 'https://github.com/ArtSabintsev/Freedom.git', :branch => 'swift4.2' # Swift 4.2
pod 'Freedom', :git => 'https://github.com/ArtSabintsev/Freedom.git', :branch => 'swift4.1' # Swift 4.1
pod 'Freedom', :git => 'https://github.com/ArtSabintsev/Freedom.git', :branch => 'swift3.2' # Swift 3.2
pod 'Freedom', :git => 'https://github.com/ArtSabintsev/Freedom.git', :branch => 'swift3.1' # Swift 3.1

Carthage

github "ArtSabintsev/Freedom" // Swift 5.1+
github "ArtSabintsev/Freedom", "swift5.0" // Swift 5.0
github "ArtSabintsev/Freedom", "swift4.2" // Swift 4.2
github "ArtSabintsev/Freedom", "swift4.1" // Swift 4.1
github "ArtSabintsev/Freedom", "swift3.2" // Swift 3.2
github "ArtSabintsev/Freedom", "swift3.1" // Swift 3.1

Swift Package Manager (Swift 包管理器)

.Package(url: "https://github.com/ArtSabintsev/Freedom.git", majorVersion: 2)

Usage (用法)

Open your Info.plist file, and add the following URL schemes to the LSApplicationQueriesSchemes key (打开你的 Info.plist 文件,并将以下 URL Schemes 添加到 LSApplicationQueriesSchemes 键中)

<key>LSApplicationQueriesSchemes</key>
<array>
  <string>brave</string>
  <string>dolphin</string>
  <string>firefox</string>
  <string>firefox-focus</string>
  <string>googlechrome</string>
</array>

Add the following code to some actionable/tappable element in your project. In this example, I am using an IBAction from a UIButton. (将以下代码添加到你项目中的一些可操作/可点击的元素中。在这个例子中,我使用的是 UIButton 的 IBAction。)

@IBAction func openURL(_ sender: UIButton) {

       // A Sample URL that just happens to be my personal website.
       let url = URL(string: "http://www.sabintsev.com")!

       // Enable Debug Logs (disabled by default)
       Freedom.debugEnabled = true

       // Fetch activities for Safari and all third-party browsers supported by Freedom (see screenshot).
       let activities = Freedom.browsers()

       // Alternatively, one could select a specific browser (or browsers).
       // let activities = Freedom.browsers([.chrome])
       let vc = UIActivityViewController(activityItems: [url], applicationActivities: activities)

       present(vc, animated: true, completion: nil)
   }

Notes (注意)

Even if you enable Freedom to support all browsers via Freedom.browsers(), only the browsers installed on your users device will be visible to the them in the share sheet (i.e., UIActivityViewController). Therefore, it is beneficial to all of your users to initialize Freedom with all supported browsers. (即使你启用 Freedom 通过 Freedom.browsers() 来支持所有浏览器,只有安装在你用户设备上的浏览器才会在分享表单 (例如 UIActivityViewController) 中对他们可见。 因此,对所有用户来说,使用所有支持的浏览器来初始化 Freedom 都是有益的。)

Created and maintained by (创建并维护者)

Arthur Ariel Sabintsev