An advanced Ethereum/EVM mobile wallet
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
alpha-wallet-ios/AlphaWalletShare/ShareContextHandler.swift

47 lines
1.4 KiB

//
// ShareContextHandler.swift
// AlphaWalletShare
//
// Created by Vladyslav Shepitko on 10.11.2020.
//
import UIKit
@objc(ShareContextHandler)
class ShareContextHandler: UIResponder, NSExtensionRequestHandling {
enum AnyError: Error {
case canceled
}
var extensionContext: NSExtensionContext?
func beginRequest(with context: NSExtensionContext) {
self.extensionContext = context
guard let extensionItem = context.inputItems.first as? NSExtensionItem else {
context.cancelRequest(withError: AnyError.canceled)
return
}
let valueResolver = DefaultItemProviderValueResolver()
extensionItem.resolveAttachments(valueResolver: valueResolver) { attachment in
if let attachment = attachment, let url = attachment.url {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
self.open(url: url)
context.completeRequest(returningItems: nil)
}
} else {
context.cancelRequest(withError: AnyError.canceled)
}
}
}
private func open(url: URL) {
guard let application = UIApplication.value(forKeyPath: #keyPath(UIApplication.shared)) as? UIApplication else { return }
let selector = NSSelectorFromString("openURL:")
application.perform(selector, with: url)
}
}