Files
archived-tauri-plugin-shell/ios/Sources/ShellPlugin.swift
Amr Bashir dc10c2ca47 feat(shell): support opening URLs on mobile (#1319)
* feat(shell): support opening URLs on mobile

closes #595

* Update and rename StorePlugin.swift to ShellPlugin.swift

* unwrap

* fix func name (ios)

* use undeprecated func if avail

---------

Co-authored-by: fabianlars <fabianlars@fabianlars.de>

Committed via a GitHub action: https://github.com/tauri-apps/plugins-workspace/actions/runs/9103843281

Co-authored-by: amrbashir <amrbashir@users.noreply.github.com>
2024-05-15 23:10:55 +00:00

35 lines
848 B
Swift

// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
import Foundation
import SwiftRs
import Tauri
import UIKit
import WebKit
class ShellPlugin: Plugin {
@objc public func open(_ invoke: Invoke) throws {
do {
let urlString = try invoke.parseArgs(String.self)
if let url = URL(string: urlString) {
if #available(iOS 10, *) {
UIApplication.shared.open(url, options: [:])
} else {
UIApplication.shared.openURL(url)
}
}
invoke.resolve()
} catch {
invoke.reject(error.localizedDescription)
}
}
}
@_cdecl("init_plugin_shell")
func initPlugin() -> Plugin {
return ShellPlugin()
}