Using the SDK

Hub for using the Apphud SDK after install — initialization, products, purchases, subscription status, promoted purchases, eligibility checks, and integration testing.

Using Apphud SDK:

After you successfully installed Apphud SDK follow these guides on how to:

Additional Resources

Migrate Existing Paying Users

If your app has existing paying users, you need to migrate them to Apphud. Please our Data Migration Guide for details.

Prepare SDK for Integrations

Some integrations require you to match user ids between Apphud and corresponding integration. For example, if you want to use AppsFlyer integration, you must submit AppsFlyer attribution with AppsFlyer ID to Apphud.
Please see the documentation guide for your desired integration.

Configure Push Notifications (iOS)

Configuring push notifications is highly recommended in order to use Rules – a powerful feature that lets you increase your app revenue by automatically offering a discount to a user at the specified moment.

User Properties

Apphud SDK allows you to pass User Properties, which can later be used in Dashboard Charts and User filtering. See User Properties guide for details.

Handle Promoted In-App Purchases (iOS)

📘

Note

Do not get confused with Promotional Offers! Promoted in-app purchases are the ones that appear in the App Store page.

If you have in-app purchases that can be purchased directly from the App Store, you should implement a logic to continue a payment in the app.

Requirements (SDK 4.5.0+)

Starting with SDK 4.5.0, promoted in-app purchases are handled through StoreKit 2 PurchaseIntent, which requires iOS 16.4+ / macOS 14.4+. On earlier OS versions the SDK does not handle promoted purchases. Promoted purchases are not available in Mac Catalyst apps or in iPhone/iPad apps running on visionOS (Apple limitation).

To continue an in-app purchase transaction initiated from the App Store page, implement the delegate method below. Return a callback block to start the purchase right away, or return nil to skip it (for example, save the product and start the purchase yourself later). The callback is called when the purchase completes.

@available(iOS 16.4, macOS 14.4, *)
func apphudShouldStartAppStoreDirectPurchase(product: Product) -> ((ApphudPurchaseResult) -> Void)? {
    return { result in
        // handle the purchase result
    }
}
func apphudShouldStartAppStoreDirectPurchase(_ product: SKProduct) -> ((ApphudPurchaseResult) -> Void)? {
    // manage your UI here, show a progress hud, etc.
    let callback : ((ApphudPurchaseResult) -> Void) = { result in 
        // check the result, hide a progress hud, etc.
    }
    return callback
}
- (void (^)(ApphudPurchaseResult * _Nonnull))apphudShouldStartAppStoreDirectPurchase:(SKProduct *)product {
    // manage your UI here, show a progress hud, etc.
    return ^(ApphudPurchaseResult * _Nonnull result) {
        // check the result, hide a progress hud, etc.
    };
}

product in the Product-based method is a StoreKit 2 Product. This method is also called for win-back offers accepted outside your app (iOS 18+).

The SKProduct-based method still works: the SDK calls it as a fallback when the Product-based method is not implemented. Objective-C apps keep using it — the StoreKit 2 Product type is not available from Objective-C. If you implement both, only the Product-based method is called.

You must return a callback block which will be called when a payment is finished. If you don't implement this method or return nil then a payment will not start; you can also save the product and return nil to initiate a payment later by yourself. You can also read Apple documentation for details.

Testing Integrations in Sandbox

To test integrations, ensure that test credentials are provided in your integration settings (if available) and make a sandbox in-app purchase.

📘

Note

Starting iOS 14 you can reset your trial eligibility in iOS Settings > App Store

On Android, you can cancel your existing sandbox subscriptions in Google Play app.

For more details regarding Testing In-App Purchases, read SDK Testing (iOS) and SDK Testing (Android) guides.

Apphud will send all subscription events of current user to your test analytics, if test credentials are set in integration settings.

📘

Note

Sandbox events will never be sent to your production integrations. If test credentials are not provided, sandbox events will not be sent anywhere.

📘

Note

You can also click on "Send Test Event" near the integration's "..." button. This feature is available only for some Integrations.

User Eligibility for Introductory Offer (iOS)

You can read more about eligibility testing here.

You can use Apphud to determine if user is eligible for introductory offer:

// Check eligibility for introductory offer
Apphud.checkEligibilityForIntroductoryOffer(product: myProduct) { result in
  // handle result
}

// Check eligibility for multiple products at one call
Apphud.checkEligibilitiesForIntroductoryOffers(products: products) { resultDict in
    // handle result
}
// Check eligibility for introductory offer
[Apphud checkEligibilityForIntroductoryOfferWithProduct:myProduct callback:^(BOOL eligible) {
    // handle result
}];

// Check eligibility for multiple products at one call
[Apphud checkEligibilitiesForIntroductoryOffersWithProducts:productsArray callback:^(NSDictionary * resultDict) {
    // handle result
}];

User Eligibility for Promotional Offer (iOS)

You can read more about eligibility testing here

You can also use Apphud to determine if user is eligible for promotional offer:

// Check eligibility for promotional offer
Apphud.checkEligibilityForPromotionalOffer(product: myProduct) { result in
  // handle result
}
// Check eligibility for multiple products at one call
Apphud.checkEligibilitiesForPromotionalOffers(products: products) { resultDict in
    // handle result
}

iOS SDK Reference

iOS SDK Reference is available here.


What’s Next

Did this page help you?