mirror of
https://github.com/samsonjs/Advanced-NSOperations.git
synced 2026-03-25 08:25:47 +00:00
56 lines
1.5 KiB
Swift
56 lines
1.5 KiB
Swift
/*
|
||
Copyright (C) 2015 Apple Inc. All Rights Reserved.
|
||
See LICENSE.txt for this sample’s licensing information
|
||
|
||
Abstract:
|
||
This file contains the code to present more information about an earthquake as a modal sheet.
|
||
*/
|
||
|
||
import Foundation
|
||
import SafariServices
|
||
|
||
/// An `EarthquakeOperation` to display an `URL` in an app-modal `SFSafariViewController`.
|
||
class MoreInformationOperation: EarthquakeOperation {
|
||
// MARK: Properties
|
||
|
||
let URL: URL
|
||
|
||
// MARK: Initialization
|
||
|
||
init(URL: URL) {
|
||
self.URL = URL
|
||
|
||
super.init()
|
||
|
||
addCondition(condition: MutuallyExclusive<UIViewController>())
|
||
}
|
||
|
||
// MARK: Overrides
|
||
|
||
override func execute() {
|
||
DispatchQueue.main.async {
|
||
self.showSafariViewController()
|
||
}
|
||
}
|
||
|
||
private func showSafariViewController() {
|
||
if let context = UIApplication.shared.keyWindow?.rootViewController {
|
||
let configuration = SFSafariViewController.Configuration()
|
||
configuration.entersReaderIfAvailable = false
|
||
let safari = SFSafariViewController(url: URL, configuration: configuration)
|
||
safari.delegate = self
|
||
context.present(safari, animated: true, completion: nil)
|
||
}
|
||
else {
|
||
finish()
|
||
}
|
||
}
|
||
}
|
||
|
||
extension MoreInformationOperation: SFSafariViewControllerDelegate {
|
||
func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
|
||
controller.dismiss(animated: true) {
|
||
self.finish()
|
||
}
|
||
}
|
||
}
|