StoreKit: AppStore missing?
Yesterday I was looking at the latest StoreKit docs and noticed that SKPaymentQueue is deprecated and has been replaced by AppStore which seems to be missing in robovm.
Can someone create the bindings for this?
@dkimitsa Can you comment on this? Happy to contribute via patron if it helps
@davidgiga1993 hi, sorry for delay with replay
issue here is that AppStore is Swift framework and can't be bind directly. To provide RoboBindings it has to be wrapped by ObjC wrapper. and than binding to be made. Will do test run this weekend and also provide a tutorial how to cover such kind of things.
@davidgiga1993 hi, just a small update.
it took lot more time that expected. it like 8K of swift source to be wrapped into ObjC compatible.
(also haven't written anything more complex than hello world apps in Swift so this made start slower than expected)
I'm currently somewhere in middle of Product class. Hope will have some draft code to play with in few days.
in general process looks like following: swift -> objc compatible wrappers (manual) -> java binding (bro-get semi-auto) -> Kotlin (optional)
kotlin here is nice to have as AppStore is async beast and would be nicely put on coroutines. as dealing with callbacks in every AppStore invocation in java might be quite dull.
Thanks for looking into it! Sadly I can't use Kotlin in my project (for various reasons), so good old java it is :)
@davidgiga1993 hey, it took a bit as there was a bit of coding involved. in general accessing Swift API is a complicated process as can't be automated (like binding objc with bro-gen).
long story short: StoryKit is wrapped with ObjC wrappers into StoryKitRvm framework. Last one was bind with bro-gen into Java api. Additionally kotlin extensions were added to provide suspendable coroutine API (StoreKit2 is built with concurrency in mind).
all these things currently pushed to https://github.com/dkimitsa/robovm-cocoatouch-swift/tree/main/storekit . before better place in RoboVM source is found for it.
also binaries deployed to sonatype maven and accessible as dependency (it contains StoryKitRvm binary as well).
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
}
dependencies {
implementation "io.github.dkimitsa.robovm:robopods-storekit-swift:18.2.0.1-SNAPSHOT"
}
API is usable similar way as per Apple docs:
Java:
Product.getProducts(NSArray.fromStrings("product.id.1"), (products, nsError) -> {
if (nsError != null) {
// handle error
return;
}
// handle products
});
or kotlin:
scope.launch(Dispatchers.Main) {
try {
val storeProducts = ProductKt.getProducts(listOf("product.id.1"))
} catch(e: NSErrorException) {
e.printStackTrace()
}
}
For testing I've ported Apple's Implementing a store in your app using the StoreKit API , it is available as part of alt-pods-tests repository:
https://github.com/dkimitsa/alt-pods-tests/tree/master/cocoatouch-swift-storekit
It's an example of how to use StoreKit asynchronously using kotlin coroutines.
For testing it is possible to use store kit testing configurations but there is a trick deploying it (Setting up StoreKit Testing in Xcode ).
However, RoboVM doesn't support configuring target with .storekit file but there is a trick how to get it deployed:
- setup xcode project with same bundle id and setup StoreKit testing;
- run it from xcode;
- after this run RoboVM app under same bundle id (it will have storekit configured as in Xcode run)
Thanks a lot for this! I already migrated to it yesterday and everything seems to work perfectly so far.
@davidgiga1993 hey, there several bugs were fixed, check the repo/commit for details.
also as testing exercise have adde it to gdx-pay https://github.com/libgdx/gdx-pay/pull/273
I did some more testing and it's crashing immediately upon startup on iOS 14,15. I know these APIs are not available on 14, and I'm not running that code on 14 (I'm using the old legacy API), but the app should nevertheless still start when the new storekit isn't executed.
Currently I'm getting the following linker warning:
ld: warning: dylib (/Users/david/.robovm/cache/ios/arm64-simulator/release/Users/david/.gradle/caches/modules-2/files-2.1/io.github.dkimitsa.robovm/robopods-storekit-swift/18.2.0.1-SNAPSHOT/553ae25a97cd9c8b66630fa5fa24271671319c49/robopods-storekit-swift-18.2.0.1-SNAPSHOT.jar.extracted/META-INF/robovm/ios/libs/StoreKitRvm.xcframework/ios-arm64_x86_64-simulator/StoreKitRvm.framework/StoreKitRvm) was built for newer iOS Simulator version (18.2) than being linked (14.0)
Followed by a crash on iOS 15 when launching the app:
Termination Reason: DYLD 4 Symbol missing
Symbol not found: _$s10Foundation22_convertErrorToNSErrorySo0E0Cs0C0_pF
Referenced from: /Users/USER/Library/Developer/CoreSimulator/Devices/85788559-AF91-4A44-BB3B-F2E4B140B637/data/Containers/Bundle/Application/E3D7699B-B1C4-4AD1-A4CC-60DEECEE3319/IOSLauncher.app/Frameworks/StoreKitRvm.framework/StoreKitRvm
Expected in: /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 15.5.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/Foundation.framework/Foundation
(terminated at launch; ignore backtrace)
Update: I'll be fixing the @available attributes and creating a MR so it runs on older iOS versions without crashing
@dkimitsa I've created a draft PR https://github.com/dkimitsa/robovm-cocoatouch-swift/pull/1 which still needs some input from your side as I don't understand this compiler error. I see that the lib binary has different dynlib search paths when changing the target ios version
@davidgiga1993 thx, i've done similar fix myself. re-deployed, starting on ios15.2, had no time to do deeper test that just compile and start
Is there a way to get this running on iOS 11 as well? I know it's a niche request but quite a few of my app users are enterprises / fixed installed devices with old iOS versions
as an option would be not link with StoreKitRvm framework but load it manually. don't know if there is such option in robovm config (to deploy with dynamic lib but not link it). need to check
Hi Did you had time to check it?
hi, sorry for late response. It is available out of box now, will share possible options till end of the day
No worries! Should this already work with targetsdk 11? I just tried and I'm getting the same libswiftXPC.dylib is not found in swift paths error but I might be doing something wrong
Friendly ping :)
hi @davidgiga1993 )
I'm keeping it in mind. had to deal with #808 first as libswiftXPC.dylib might require compiler changes.
plan to work on it tomorrow.
thx
hi @davidgiga1993
could you please provide more info and scenario when you are having troubles with libswiftXPC.dylib ?
and scenarios related to ios11
thx
hi @davidgiga1993 could you please provide more info and scenario when you are having troubles with
libswiftXPC.dylib? and scenarios related to ios11
When trying to build my app using the cocoatouch-swift-storekit I get the libswiftXPC.dylib is not found in swift paths error.
The app is targeting ios 11:
<key>MinimumOSVersion</key>
<string>11.0</string>
I'm currently using <iosSdkVersion>18.2</iosSdkVersion> for compiling.
Compile is done using the createIPA task of the robovm gradle plugin
what version of robovm are you using, this kind on issue was fixed some time ago https://github.com/MobiVM/robovm/pull/783
in 2.3.22
Aah I'm still on 2.3.20, I'll update and report back later
@davidgiga1993 have pushed few changes related to error handling recently to https://github.com/dkimitsa/robovm-cocoatouch-swift/tree/main/storekit
I did some rough testing yesterday and it seems to build and run fine :) I'll soon release this to beta users and get more feedback
Okay while it now compiles correctly, libgdx doesn't run anymore at all on older iOS versions, see https://github.com/libgdx/libgdx/issues/7649
StoreKit2 bindings were moved to https://github.com/MobiVM/robovm-cocoatouch-swift and released to Sonatype:
It was split into Java bindings:
implementation("com.mobidevelop.robovm:robopods-swift-storekit2:18.2.0.1")
and kotlin wrappers (with coroutine flavour):
implementation("com.mobidevelop.robovm:robopods-swift-storekit2-kt:18.2.0.1")