macOS in-app purchases via dylib - is it possible? alternatives? suggestions?

19 Views Asked by At

I've got a big macOS program, developed with Lazarus/FPC/C (i.e. without Xcode) and I need to implement macOS in-app purchases in order to submit it on Apple's App Store. With 1M+ lines of code, rewriting it in Swift is not an option.

One option that I'm testing is to write a DYLIB in Swift using Xcode, implementing all the necessary StoreKit functionality, and link to this library from the main non-Xcode program. I have actually done all that, and things almost seems to work... but "almost" is not good enough :(

I created a storekit configuration file and some test non-consumable products for local testing, but no matter what I do, I cannot manage to launch a purchase action. During initialization of the Store class, when I send productIds to the Product class to make an array of [Product], I always get an empty array. When I do virtually the same thing with an iOS project, I do get a list of test products.

Is it that a DYLIB cannot hook up with the StoreKit 2 testing system? If so, is the problem only because it's the testing mode that is used, and would it work with real products? Or is it impossible for a DYLIB to to any storekit-related work? (note that my DYLIB compiles successfully, and the storekit connection seems to work - but I just can't get any products loaded at all. Or am I doing anything wrong with the code?

And if a dylib is positively forbidden from fully implementing storekit functionality, do you have any other suggestions for adding in-app purchases to a macOS application written in Lazarus/FPC?

These are the lines of code which don't produce the expected array of Product. I'm sure the ids in the dictionary are correct and correspond to those in the configuration file.

@MainActor
func requestProducts() async {
    do {  // productDict contains name-id pairs of products that I created in the storekit configuration file.
        log = "req values: "
        for v in productDict.values {  // here I make sure I have the ids in the dict
            log += " " + v + " "
        }
        // here I try to create the array of Product...
        let storeProducts = try await Product.products(for: productDict.values)
        log += " assigned"  // now storeProducts should contain the items...
        for product in storeProducts {
            log += " \(product.id)"  
            // here I should find the created products, but it's empty
0

There are 0 best solutions below