initConnection
Initialize the store connection and wait for a successful result before starting store operations.
iOS: Verifies AppStore.canMakePayments, receives promoted IAPs through PurchaseIntent.intents on iOS 16.4+ (and SKPaymentQueue only on iOS 15–16.3), and starts a Transaction.updates listener that drives the purchase event stream. Safe to call repeatedly. Apple docs. React Native and Expo can connect on demand on iOS, but an explicit call keeps listener setup and cross-platform gating predictable. Android: Starts BillingClient and waits for onBillingSetupFinished. React Native and Expo do not open it implicitly; wait for true or the hook's connected flag before another Play Billing call. Meta Horizon additionally requires a current foreground Activity; initialization fails with MissingCurrentActivity instead of falling back to an application context. Google docs.
Signature
func initConnection() async throws -> BoolParameters#
Pass an optional InitConnectionConfig — Android billing program flags. iOS ignores Android-specific fields.
enableBillingProgramAndroid(optional,BillingProgramAndroid) — Android. Enable a Play Billing program at connection time.EXTERNAL_CONTENT_LINKandEXTERNAL_OFFERrequire Billing 8.2.0+;EXTERNAL_PAYMENTSrequires Billing 8.3.0+ (Japan only);BILLING_CHOICEis available in OpenIAP Spec 2.1.0 /openiap-google2.3.0 and requires Billing 9.1.0+.billingChoiceScreenTypeAndroid(optional,BillingChoiceScreenTypeAndroid) — OpenIAP Spec 2.1.0 / openiap-google 2.3.0. Requires Play Billing 9.1.0+ and must match the Billing Choice renderer configured in Play Console. Defaults toGOOGLE_RENDERED; setDEVELOPER_RENDEREDwhen your app owns the choice screen.
Returns#
Promise<boolean> — true once the platform billing client is connected.
Throws#
When the platform billing client fails to initialize.
Example
import OpenIap
let connected = try await OpenIapModule.shared.initConnection()
precondition(connected, "Store connection failed")See InitConnectionConfig for the full list of supported config fields (enableBillingProgramAndroid, and billingChoiceScreenTypeAndroid).