Skip to content

Commit b148d10

Browse files
authored
Support ios 16 (#7)
* itroduce `Ios17Specific` as an Option-like that forces the user to handle the case that this runs on a lower-than-17 iOS and might not be available
1 parent 40e5658 commit b148d10

File tree

11 files changed

+77
-49
lines changed

11 files changed

+77
-49
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
### Changed
11+
* make `Transaction` `reason` and `storefront` available only ios `17.0` or up
12+
* make package iOS `16.0` compatible
13+
* remove `currency_code` as it was deprecated in iOS `16.0`
14+
1015
## [0.5.2] - 2024-01-11
1116

1217
### Added

Package.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import PackageDescription
55

66
let package = Package(
77
name: "bevy_ios_iap",
8-
platforms: [.iOS("17.0")],
8+
platforms: [.iOS("16.0")],
99
products: [
1010
// Products define the executables and libraries a package produces, making them visible to other packages.
1111
.library(
@@ -18,9 +18,9 @@ let package = Package(
1818
.binaryTarget(
1919
name: "RustXcframework",
2020
// for local development:
21-
// path: "RustXcframework.xcframework"),
22-
url: "https://github.com/rustunit/bevy_ios_iap/releases/download/rs-0.5.2/RustXcframework.xcframework.zip",
23-
checksum: "4564b6fb319576e23e73e79618337825f59fe009e2cbc96e98796cdc46fc2da1"),
21+
path: "RustXcframework.xcframework"),
22+
// url: "https://github.com/rustunit/bevy_ios_iap/releases/download/rs-0.5.2/RustXcframework.xcframework.zip",
23+
// checksum: "4564b6fb319576e23e73e79618337825f59fe009e2cbc96e98796cdc46fc2da1"),
2424
.target(
2525
name: "bevy_ios_iap",
2626
dependencies: ["RustXcframework"]),

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ fn process_iap_events(
134134
}
135135
```
136136

137+
## Local development
138+
139+
1. Build locally via `just build`
140+
2. Change the `Package.swift` to use the locally built `xcframework`
141+
3. Switch XCode package dependency to use local repo via path
142+
4. Patch `Cargo.toml` to use local repository
143+
137144
## Our Other Crates
138145

139146
- [bevy_debug_log](https://github.com/rustunit/bevy_debug_log)

RustXcframework.xcframework/ios-arm64/Headers/bevy_ios_iap.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,12 @@ void* __swift_bridge__$IosIapEnvironment$sandbox(void);
259259
void* __swift_bridge__$IosIapEnvironment$production(void);
260260
void* __swift_bridge__$IosIapEnvironment$xcode(void);
261261
void* __swift_bridge__$IosIapStorefront$storefront(void* id, void* country_code);
262-
void* __swift_bridge__$IosIapTransaction$new_transaction(uint64_t id, void* product_id, void* app_bundle_id, uint64_t purchase_date, uint64_t original_purchase_date, int32_t purchased_quantity, void* storefront_country_code, uint64_t signed_date, bool is_upgraded, uint64_t original_id, void* json_representation, void* product_type, void* reason, void* environment, void* storefront);
262+
void* __swift_bridge__$IosIapTransaction$new_transaction(uint64_t id, void* product_id, void* app_bundle_id, uint64_t purchase_date, uint64_t original_purchase_date, int32_t purchased_quantity, void* storefront_country_code, uint64_t signed_date, bool is_upgraded, uint64_t original_id, void* json_representation, void* product_type, void* environment);
263+
void __swift_bridge__$IosIapTransaction$add_storefront(void* t, void* store);
264+
void __swift_bridge__$IosIapTransaction$add_reason(void* t, void* reason);
263265
void __swift_bridge__$IosIapTransaction$add_revocation(void* t, uint64_t date);
264266
void __swift_bridge__$IosIapTransaction$add_expiration(void* t, uint64_t date);
265267
void __swift_bridge__$IosIapTransaction$add_currency(void* t, void* currency);
266-
void __swift_bridge__$IosIapTransaction$add_currency_code(void* t, void* code);
267268
void __swift_bridge__$IosIapTransaction$revocation_reason(void* t, void* reason);
268269
void __swift_bridge__$IosIapTransaction$web_order_line_item_id(void* t, void* id);
269270
void __swift_bridge__$IosIapTransaction$subscription_group_id(void* t, void* id);

RustXcframework.xcframework/ios-arm64_x86_64-simulator/Headers/bevy_ios_iap.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,12 @@ void* __swift_bridge__$IosIapEnvironment$sandbox(void);
259259
void* __swift_bridge__$IosIapEnvironment$production(void);
260260
void* __swift_bridge__$IosIapEnvironment$xcode(void);
261261
void* __swift_bridge__$IosIapStorefront$storefront(void* id, void* country_code);
262-
void* __swift_bridge__$IosIapTransaction$new_transaction(uint64_t id, void* product_id, void* app_bundle_id, uint64_t purchase_date, uint64_t original_purchase_date, int32_t purchased_quantity, void* storefront_country_code, uint64_t signed_date, bool is_upgraded, uint64_t original_id, void* json_representation, void* product_type, void* reason, void* environment, void* storefront);
262+
void* __swift_bridge__$IosIapTransaction$new_transaction(uint64_t id, void* product_id, void* app_bundle_id, uint64_t purchase_date, uint64_t original_purchase_date, int32_t purchased_quantity, void* storefront_country_code, uint64_t signed_date, bool is_upgraded, uint64_t original_id, void* json_representation, void* product_type, void* environment);
263+
void __swift_bridge__$IosIapTransaction$add_storefront(void* t, void* store);
264+
void __swift_bridge__$IosIapTransaction$add_reason(void* t, void* reason);
263265
void __swift_bridge__$IosIapTransaction$add_revocation(void* t, uint64_t date);
264266
void __swift_bridge__$IosIapTransaction$add_expiration(void* t, uint64_t date);
265267
void __swift_bridge__$IosIapTransaction$add_currency(void* t, void* currency);
266-
void __swift_bridge__$IosIapTransaction$add_currency_code(void* t, void* code);
267268
void __swift_bridge__$IosIapTransaction$revocation_reason(void* t, void* reason);
268269
void __swift_bridge__$IosIapTransaction$web_order_line_item_id(void* t, void* id);
269270
void __swift_bridge__$IosIapTransaction$subscription_group_id(void* t, void* id);

Sources/bevy_ios_iap/BevyIosIAP.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,8 @@ public func convert_transaction(_ transaction: (Transaction)) throws -> IosIapTr
227227
} else {
228228
IosIapProductType.new_auto_renewable()
229229
}
230-
231-
let reason = if transaction.reason == Transaction.Reason.purchase {
232-
IosIapTransactionReason.purchase()
233-
} else {
234-
IosIapTransactionReason.renewal()
235-
}
230+
231+
let jsonRepresentation = String(decoding: transaction.jsonRepresentation, as: UTF8.self)
236232

237233
let env = if transaction.environment == AppStore.Environment.xcode {
238234
IosIapEnvironment.xcode()
@@ -242,10 +238,6 @@ public func convert_transaction(_ transaction: (Transaction)) throws -> IosIapTr
242238
IosIapEnvironment.production()
243239
}
244240

245-
let store = IosIapStorefront.storefront(transaction.storefront.id, transaction.storefront.countryCode)
246-
247-
let jsonRepresentation = String(decoding: transaction.jsonRepresentation, as: UTF8.self)
248-
249241
var t = IosIapTransaction.new_transaction(
250242
transaction.id,
251243
transaction.productID,
@@ -259,16 +251,24 @@ public func convert_transaction(_ transaction: (Transaction)) throws -> IosIapTr
259251
transaction.originalID,
260252
jsonRepresentation,
261253
type,
262-
reason,
263-
env,
264-
store)
254+
env)
265255

266-
if let appAccountToken = transaction.appAccountToken {
267-
IosIapTransaction.app_account_token(t, appAccountToken.uuidString)
256+
if #available(iOS 17.0, *) {
257+
let store = IosIapStorefront.storefront(transaction.storefront.id, transaction.storefront.countryCode)
258+
259+
IosIapTransaction.add_storefront(t, store)
260+
261+
let reason = if transaction.reason == Transaction.Reason.purchase {
262+
IosIapTransactionReason.purchase()
263+
} else {
264+
IosIapTransactionReason.renewal()
265+
}
266+
267+
IosIapTransaction.add_reason(t, reason)
268268
}
269269

270-
if let currencyCode = transaction.currencyCode {
271-
IosIapTransaction.add_currency_code(t, currencyCode)
270+
if let appAccountToken = transaction.appAccountToken {
271+
IosIapTransaction.app_account_token(t, appAccountToken.uuidString)
272272
}
273273

274274
if let currency = transaction.currency {

Sources/bevy_ios_iap/bevy_ios_iap.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,8 +1162,16 @@ public class IosIapTransaction: IosIapTransactionRefMut {
11621162
}
11631163
}
11641164
extension IosIapTransaction {
1165-
class public func new_transaction<GenericIntoRustString: IntoRustString>(_ id: UInt64, _ product_id: GenericIntoRustString, _ app_bundle_id: GenericIntoRustString, _ purchase_date: UInt64, _ original_purchase_date: UInt64, _ purchased_quantity: Int32, _ storefront_country_code: GenericIntoRustString, _ signed_date: UInt64, _ is_upgraded: Bool, _ original_id: UInt64, _ json_representation: GenericIntoRustString, _ product_type: IosIapProductType, _ reason: IosIapTransactionReason, _ environment: IosIapEnvironment, _ storefront: IosIapStorefront) -> IosIapTransaction {
1166-
IosIapTransaction(ptr: __swift_bridge__$IosIapTransaction$new_transaction(id, { let rustString = product_id.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), { let rustString = app_bundle_id.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), purchase_date, original_purchase_date, purchased_quantity, { let rustString = storefront_country_code.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), signed_date, is_upgraded, original_id, { let rustString = json_representation.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), {product_type.isOwned = false; return product_type.ptr;}(), {reason.isOwned = false; return reason.ptr;}(), {environment.isOwned = false; return environment.ptr;}(), {storefront.isOwned = false; return storefront.ptr;}()))
1165+
class public func new_transaction<GenericIntoRustString: IntoRustString>(_ id: UInt64, _ product_id: GenericIntoRustString, _ app_bundle_id: GenericIntoRustString, _ purchase_date: UInt64, _ original_purchase_date: UInt64, _ purchased_quantity: Int32, _ storefront_country_code: GenericIntoRustString, _ signed_date: UInt64, _ is_upgraded: Bool, _ original_id: UInt64, _ json_representation: GenericIntoRustString, _ product_type: IosIapProductType, _ environment: IosIapEnvironment) -> IosIapTransaction {
1166+
IosIapTransaction(ptr: __swift_bridge__$IosIapTransaction$new_transaction(id, { let rustString = product_id.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), { let rustString = app_bundle_id.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), purchase_date, original_purchase_date, purchased_quantity, { let rustString = storefront_country_code.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), signed_date, is_upgraded, original_id, { let rustString = json_representation.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), {product_type.isOwned = false; return product_type.ptr;}(), {environment.isOwned = false; return environment.ptr;}()))
1167+
}
1168+
1169+
class public func add_storefront(_ t: IosIapTransactionRefMut, _ store: IosIapStorefront) {
1170+
__swift_bridge__$IosIapTransaction$add_storefront(t.ptr, {store.isOwned = false; return store.ptr;}())
1171+
}
1172+
1173+
class public func add_reason(_ t: IosIapTransactionRefMut, _ reason: IosIapTransactionReason) {
1174+
__swift_bridge__$IosIapTransaction$add_reason(t.ptr, {reason.isOwned = false; return reason.ptr;}())
11671175
}
11681176

11691177
class public func add_revocation(_ t: IosIapTransactionRefMut, _ date: UInt64) {
@@ -1178,10 +1186,6 @@ extension IosIapTransaction {
11781186
__swift_bridge__$IosIapTransaction$add_currency(t.ptr, {currency.isOwned = false; return currency.ptr;}())
11791187
}
11801188

1181-
class public func add_currency_code<GenericIntoRustString: IntoRustString>(_ t: IosIapTransactionRefMut, _ code: GenericIntoRustString) {
1182-
__swift_bridge__$IosIapTransaction$add_currency_code(t.ptr, { let rustString = code.intoRustString(); rustString.isOwned = false; return rustString.ptr }())
1183-
}
1184-
11851189
class public func revocation_reason(_ t: IosIapTransactionRefMut, _ reason: IosIapRevocationReason) {
11861190
__swift_bridge__$IosIapTransaction$revocation_reason(t.ptr, {reason.isOwned = false; return reason.ptr;}())
11871191
}

bevy_ios_iap/src/native.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,19 +132,19 @@ mod ffi {
132132
original_id: u64,
133133
json_representation: String,
134134
product_type: IosIapProductType,
135-
reason: IosIapTransactionReason,
136135
environment: IosIapEnvironment,
137-
storefront: IosIapStorefront,
138136
) -> IosIapTransaction;
139137
#[swift_bridge(associated_to = IosIapTransaction)]
138+
fn add_storefront(t: &mut IosIapTransaction, store: IosIapStorefront);
139+
#[swift_bridge(associated_to = IosIapTransaction)]
140+
fn add_reason(t: &mut IosIapTransaction, reason: IosIapTransactionReason);
141+
#[swift_bridge(associated_to = IosIapTransaction)]
140142
fn add_revocation(t: &mut IosIapTransaction, date: u64);
141143
#[swift_bridge(associated_to = IosIapTransaction)]
142144
fn add_expiration(t: &mut IosIapTransaction, date: u64);
143145
#[swift_bridge(associated_to = IosIapTransaction)]
144146
fn add_currency(t: &mut IosIapTransaction, currency: IosIapCurrency);
145147
#[swift_bridge(associated_to = IosIapTransaction)]
146-
fn add_currency_code(t: &mut IosIapTransaction, code: String);
147-
#[swift_bridge(associated_to = IosIapTransaction)]
148148
fn revocation_reason(t: &mut IosIapTransaction, reason: IosIapRevocationReason);
149149
#[swift_bridge(associated_to = IosIapTransaction)]
150150
fn web_order_line_item_id(t: &mut IosIapTransaction, id: String);

bevy_ios_iap/src/transaction.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ use crate::{
33
IosIapTransactionReason,
44
};
55

6+
/// Marks an iOS 17 version dependant value. If it is set then the device supports minimum iOS 17.
7+
/// Not using `Option` here to be explicit about the cause for a missing value and to handle it with caution.
8+
#[derive(Debug, Clone, Copy)]
9+
pub enum Ios17Specific<T> {
10+
/// The value is available on iOS 17.0 and later.
11+
Available(T),
12+
/// The value is not available on iOS 17.0 and later.
13+
NotAvailable,
14+
}
15+
616
/// Representation of a Transaction.
717
/// Mirrors the Transcation type in Apple's StoreKit2 closely.
818
/// See official docs for more details on the individual fields.
@@ -24,11 +34,10 @@ pub struct IosIapTransaction {
2434
pub is_upgraded: bool,
2535
pub json_representation: String,
2636
pub product_type: IosIapProductType,
27-
pub storefront: IosIapStorefront,
37+
pub storefront: Ios17Specific<IosIapStorefront>,
38+
pub reason: Ios17Specific<IosIapTransactionReason>,
2839
pub environment: IosIapEnvironment,
29-
pub reason: IosIapTransactionReason,
3040
pub currency: Option<IosIapCurrency>,
31-
pub currency_code: Option<String>,
3241
pub revocation_reason: Option<IosIapRevocationReason>,
3342
/// representing a UUID
3443
pub app_account_token: Option<String>,
@@ -62,9 +71,7 @@ impl IosIapTransaction {
6271
original_id: u64,
6372
json_representation: String,
6473
product_type: IosIapProductType,
65-
reason: IosIapTransactionReason,
6674
environment: IosIapEnvironment,
67-
storefront: IosIapStorefront,
6875
) -> Self {
6976
Self {
7077
id,
@@ -75,24 +82,31 @@ impl IosIapTransaction {
7582
purchased_quantity,
7683
storefront_country_code,
7784
signed_date,
78-
reason,
7985
app_account_token: None,
8086
json_representation,
8187
product_type,
8288
revocation_date: None,
8389
expiration_date: None,
8490
is_upgraded,
8591
environment,
86-
storefront,
8792
currency: None,
88-
currency_code: None,
8993
original_id,
9094
revocation_reason: None,
9195
subscription_group_id: None,
9296
web_order_line_item_id: None,
97+
storefront: Ios17Specific::NotAvailable,
98+
reason: Ios17Specific::NotAvailable,
9399
}
94100
}
95101

102+
pub fn add_storefront(t: &mut Self, store: IosIapStorefront) {
103+
t.storefront = Ios17Specific::Available(store);
104+
}
105+
106+
pub fn add_reason(t: &mut Self, reason: IosIapTransactionReason) {
107+
t.reason = Ios17Specific::Available(reason);
108+
}
109+
96110
pub fn add_revocation(t: &mut Self, date: u64) {
97111
t.revocation_date = Some(date);
98112
}
@@ -105,10 +119,6 @@ impl IosIapTransaction {
105119
t.currency = Some(currency);
106120
}
107121

108-
pub fn add_currency_code(t: &mut Self, code: String) {
109-
t.currency_code = Some(code);
110-
}
111-
112122
pub fn revocation_reason(t: &mut Self, reason: IosIapRevocationReason) {
113123
t.revocation_reason = Some(reason);
114124
}

bevy_ios_iap_egui/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.1"
44
edition = "2021"
55

66
[dependencies]
7-
bevy_ios_iap = "0.5"
7+
bevy_ios_iap = { path = "../bevy_ios_iap" }
88
bevy = { version = "0.15", default-features = false }
99
bevy_egui = { version = "0.32", default-features = false }
1010
egui_extras = { version = "0.30" }

0 commit comments

Comments
 (0)