Sandun Rajitha
Sandun Rajitha

Reputation: 51

‘Add eSIM’ option in the eSIM QR code long press context menu | WKWebView vs SFSafariViewController

I’m trying to show a eSIM QR code via a WKWebView and get the ‘Add eSIM’ option when the user long press on the QR code. But when I long press on my device it doesn’t show the ‘Add eSIM’ option in the context menu.

with WKWebView:

enter image description here

struct QRView: UIViewRepresentable {
    let url: URL

    func makeUIView(context: Context) -> WKWebView {
        let webView = WKWebView()
        if let urlRequest = URL(string: url.absoluteString) {
            webView.load(URLRequest(url: urlRequest))
        }
        return webView
    }

    func updateUIView(_ uiView: WKWebView, context: Context) {}
}

Then I tried to show the QR code using SFSafariViewController. it worked fine when I used the SFSafariViewController.

with SFSafariViewController:

enter image description here

    struct QRView: UIViewControllerRepresentable {
    let urlString: String
    let width: CGFloat
    let height: CGFloat

    init(urlString: String, width: CGFloat, height: CGFloat) {
        self.urlString = urlString
        self.width = width
        self.height = height
    }

    func makeUIViewController(context: Context) -> SFSafariViewController {
        guard let url = URL(string: urlString) else {
            fatalError("Invalid URL")
        }
        let safariViewController = SFSafariViewController(url: url)
        safariViewController.preferredContentSize = CGSize(width: width, height: height)
        safariViewController.modalPresentationStyle = .formSheet
        return safariViewController
    }

    func updateUIViewController(_ uiViewController: SFSafariViewController, context: Context) {
        //
    }
}

How can I do the same with the WKWebView? Any help is appreciated.

Upvotes: 1

Views: 497

Answers (1)

Sandun Rajitha
Sandun Rajitha

Reputation: 51

There's a better way to do this From iOS 17.4 and up. Apple Supports eSIM install with Universal Link. Format goes like

https://esimsetup.apple.com/esim_qrcode_provisioning?carddata=LPA:1$GSMA_SMDP_Address$activation_code

https://developer.apple.com/documentation/ios-ipados-release-notes/ios-ipados-17_5-release-notes#New-Features

Universal Links should be all lower case. Only the GSMA activation code (QR code), passed in as carddata, is customized for the carrier’s SM-DP+ and eSIM profile. Use the iOS user agent in web requests to determine when to offer Universal Links for eSIM, which are only be enabled on iOS 17.4 and later. (92405493)

Upvotes: 1

Related Questions