9.5 C
New York
Tuesday, March 11, 2025

I Need to Open a Modal for Exterior Hyperlink in Flutter iOS, However It’s Not Working


I’m attempting to open a modal utilizing Exterior Hyperlink Account on iOS 16.0+ gadgets in my Flutter app. Nevertheless, after I name ExternalLinkAccount.open(), nothing occurs, and I don’t obtain any errors. I’m attempting the next Swift code:

import UIKit
import Flutter
import StoreKit

func openExternalLink() async throws {
    if #out there(iOS 16.0, *) {
        if ExternalLinkAccount.canOpen {
            attempt await ExternalLinkAccount.open()
        } else {
            throw NSError(area: "ExternalLinkError", code: -1, userInfo: [NSLocalizedDescriptionKey: "Cannot open external link."])
        }
    } else {
        throw NSError(area: "ExternalLinkError", code: -1, userInfo: [NSLocalizedDescriptionKey: "Unsupported iOS version."])
    }
}

@most important
@objc class AppDelegate: FlutterAppDelegate {
    override func utility(
        _ utility: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        self.window?.makeSecure() // Safe the window to stop delicate knowledge leakage
        GeneratedPluginRegistrant.register(with: self)
        setupMethodChannel(controller: window?.rootViewController as! FlutterViewController)
        return tremendous.utility(utility, didFinishLaunchingWithOptions: launchOptions)
    }
}


func setupMethodChannel(controller: FlutterViewController) {
    let methodChannel = FlutterMethodChannel(title: "external_link_account", binaryMessenger: controller.binaryMessenger)
    
    methodChannel.setMethodCallHandler { (name: FlutterMethodCall, outcome: @escaping FlutterResult) in
        if name.technique == "openLinkout" {
            if #out there(iOS 16.0, *) {
                Activity {
                    do {
                        attempt await ExternalLinkAccount.open() // Await right here
                        outcome("Hyperlink opened efficiently!")
                    } catch {
                        outcome(FlutterError(code: "ERROR", message: "Did not open hyperlink", particulars: nil))
                    }
                }
            } else {
                outcome(FlutterError(code: "OS_TOO_OLD", message: "iOS model too previous", particulars: nil))
            }
        } else {
            outcome(FlutterMethodNotImplemented)
        }
    }
}

I’m attempting to open the exterior hyperlink, however the modal shouldn’t be showing. I made certain the ExternalLinkAccount.open() perform is being known as with await, however nonetheless, nothing occurs. Questions: • Might there be a difficulty with calling ExternalLinkAccount.open()? • Is there one thing else I must do when calling this perform? • What iOS variations ought to I guarantee compatibility with? • Are there any further assets or examples about this module? Anybody who might assist can be a lot appreciated! Thanks upfront!

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles