| Crates.io | bevy_ios_iap |
| lib.rs | bevy_ios_iap |
| version | 0.6.1 |
| created_at | 2024-05-02 13:54:45.774046+00 |
| updated_at | 2025-04-29 16:55:36.868447+00 |
| description | Bevy Plugin and Swift Package to provide access to iOS native StoreKit2 from inside Bevy Apps |
| homepage | |
| repository | https://github.com/rustunit/bevy_ios_iap |
| max_upload_size | |
| id | 1227765 |
| size | 95,262 |
Provides access to iOS native StoreKit2 Swift API from inside Bevy Apps. It uses Swift-Bridge to auto-generate the glue code and transport datatypes.

Demo from our game using this crate: zoolitaire.com
Add StoreKit framework:

Go to File -> Add Package Dependencies and paste https://github.com/rustunit/bevy_ios_iap.git into the search bar on the top right:

Don't forget to configure your purchases like for any other iOS app, this guide will not focus on that, as it is the same no matter what engine you use. this guide focuses on setting things up in a bevy project.
Note:
The rust crate used must be exactly the same version as the Swift Package (for binary compatibility reasons).
I suggest using a specific version (like 0.2.0 in the screenshot) to make sure to always use binary matching versions!
cargo add bevy_ios_iap
or
# always pin to the same exact version you also of the Swift package
bevy_ios_iap = { version = "=0.2.1" }
Initialize Bevy Plugin:
// request initialisation right on startup
app.add_plugins(IosIapPlugin::new(true));
fn bevy_system(mut iap: BevyIosIap) {
// If you set the plugin to manual init, this will register the
// TranscactionObserver to listen to updates to any Transactions and trigger
// `IosIapEvents::Transaction` accordingly.
// Note: this will require the user to be logged in into their apple-id and popup a login dialog if not
bevy_ios_iap::init();
// request product details, product IDs have to be explicitly provided
iap.products(vec!["com.rustunit.zoolitaire.levelunlock".into()])
.on_response(|trigger: Trigger<Products>| match &trigger.event().0 {
IosIapProductsResponse::Done(products) => {
info!("products loaded: {}", products.len());
for p in products {
info!("product: {:?}", p);
}
}
IosIapProductsResponse::Error(e) => error!("error fetching products: {e}"),
});
// trigger a product purchase for a specific product ID
iap.purchase("com.rustunit.zoolitaire.levelunlock".into())
.on_response(|trigger: Trigger<Purchase>|{
match &trigger.event().0 {
IosIapPurchaseResponse::Success(t) => {
info!("just purchased: '{}' {}", t.product_id, t.id);
iap.finish_transaction(t.id).on_response(on_finish_transaction);
}
_ => {}
}
});
// request to restore active subscriptions and non-consumables
iap.current_entitlements()
.on_response(|trigger: Trigger<CurrentEntitlements>|{
info!("current entitlements: {}", trigger.event());
});
}
Process Response Events from iOS back to us in Rust:
fn process_iap_events(
mut events: EventReader<IosIapEvents>,
) {
for e in events.read() {
match e {
// this is triggered when a transaction verification state changes during the runtime of the app
IosIapEvents::TransactionUpdate(_) => todo!(),
}
}
}
just buildPackage.swift to use the locally built xcframeworkCargo.toml to use local repository| bevy | bevy_ios_iap |
|---|---|
| 0.15 | 0.5,main |
| 0.14 | 0.3,0.4 |
| 0.13 | 0.2 |
All code in this repository is dual-licensed under either:
at your option. This means you can select the license you prefer.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.