Код: Выделить всё
import UIKit
import Flutter
import StoreKit
func openExternalLink() async throws {
if #available(iOS 16.0, *) {
if ExternalLinkAccount.canOpen {
try await ExternalLinkAccount.open()
} else {
throw NSError(domain: "ExternalLinkError", code: -1, userInfo: [NSLocalizedDescriptionKey: "Cannot open external link."])
}
} else {
throw NSError(domain: "ExternalLinkError", code: -1, userInfo: [NSLocalizedDescriptionKey: "Unsupported iOS version."])
}
}
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
self.window?.makeSecure() // Secure the window to prevent sensitive data leakage
GeneratedPluginRegistrant.register(with: self)
setupMethodChannel(controller: window?.rootViewController as! FlutterViewController)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
func setupMethodChannel(controller: FlutterViewController) {
let methodChannel = FlutterMethodChannel(name: "external_link_account", binaryMessenger: controller.binaryMessenger)
methodChannel.setMethodCallHandler { (call: FlutterMethodCall, result: @escaping FlutterResult) in
if call.method == "openLinkout" {
if #available(iOS 16.0, *) {
Task {
do {
try await ExternalLinkAccount.open() // Await here
result("Link opened successfully!")
} catch {
result(FlutterError(code: "ERROR", message: "Failed to open link", details: nil))
}
}
} else {
result(FlutterError(code: "OS_TOO_OLD", message: "iOS version too old", details: nil))
}
} else {
result(FlutterMethodNotImplemented)
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... ot-working