1
0
mirror of https://gitlab.com/timvisee/send.git synced 2024-11-14 15:12:48 +01:00
send/ios/send-ios/ViewController.swift
2018-08-02 14:24:13 -04:00

40 lines
1.2 KiB
Swift

//
// ViewController.swift
// send-ios
//
// Created by Donovan Preston on 7/19/18.
//
import UIKit
import WebKit
class ViewController: UIViewController, WKScriptMessageHandler {
@IBOutlet var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
self.webView.frame = self.view.bounds
self.webView?.configuration.userContentController.add(self, name: "loaded")
self.webView?.configuration.userContentController.add(self, name: "copy")
if let url = Bundle.main.url(
forResource: "index",
withExtension: "html",
subdirectory: "assets") {
webView.loadFileURL(url, allowingReadAccessTo: url.deletingLastPathComponent())
}
}
public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
print("Message received: \(message.name) with body: \(message.body)")
UIPasteboard.general.string = "\(message.body)"
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}