0

I am setting up my iOS app to use the new "reader app" external link option, which means we can send people to our website to sign up instead of using in-app purchase.

Our app is written in Objective C.

The documentation from Apple says you need to use ExternalLinkAccount open() in order to spawn a modal window that warns users they are leaving your app. The problem is, I can't figure out how to use this and can't find any examples.

This is the documentation on how to set up a reader app with an external link: https://developer.apple.com/support/reader-apps/

This is the specific documentation for ExternalLinkAccount: https://developer.apple.com/documentation/storekit/externallinkaccount

I tried including StoreKit in my .m file but can't figure out how to use ExternalLinkAccount.

1 Answers1

0

Apparently StoreKit 2 interfaces are Swift-only. So you'll need to write a wrapper in Swift which is callable from Objective-C:

ExternalLinkAccountSwiftWrapper.swift:

import Foundation
import StoreKit

@available(iOS 16.0, *)
@objcMembers class ExternalLinkAccountSwiftWrapper: NSObject{
    static func canOpen() async -> Bool {
        return await ExternalLinkAccount.canOpen;
    }
    static func open() {
        Task.detached{
            do {
                try await ExternalLinkAccount.open();
            }
            catch{}
        }
    }
}

Marking the class with @objcMembers will make Xcode generate a Header-File named "(YourProjectName)-Swift.h" which can be used from your existing Objective-C code (see Call Swift function from Objective-C class).

Paul H.
  • 1
  • 1