Swiftpack.co - Package - apphud/ApphudSDK
Apphud

Apphud SDK

Apphud SDK is a lightweight open-source Swift library to manage auto-renewable subscriptions and other in-app purchases in your iOS app. No backend required.

Visit our website for details: https://apphud.com

Features

๐Ÿ‘ Integrating subscriptions using our SDK is very easy.
Apphud takes care of a subscription purchase process. Integrate SDK in just a few lines of code.

๐Ÿงพ App Store receipts validation.
Apphud validates and periodically refreshes App Store receipts to give you real-time data.

๐Ÿ•— View subscription details and transactions history.
Get expiration date, autorenew status in our SDK.

๐Ÿ•— View non-renewing purchase details and transactions history.

๐Ÿ” Determine for trial, introductory and promotional offer eligibility using our SDK.

๐Ÿ”” Receive a real-time notification when a user gets billed.
We will send you a message to Slack and Telegram immediately when a user gets billed or started trial.

๐Ÿ“Š View key subscription metrics in our dashboard.
Apphud has a convenient dashboard with key metrics of your subscriptions.

๐Ÿ”Œ Integrations. Are available on all plans. Send subscription renewal events to other mobile analytics.
Apphud reduces pain in sending all subscription events to external mobile analytics: Amplitude, Mixpanel, AppsFlyer, etc.

๐ŸŽจ Create subscription purchase screens without coding in our visual web editor.
You don't need to develop purchase screens. Just pick a template and modify it. So easy! For now only promotional purchase screen are available, initial purchase screens will be available soon.

โœ” Promotional subscription offers support.
Use Apphud to easily give a discount for existing and lapsed customers. No backend required.

๐Ÿ’ฑ User local currency real-time conversion.

๐Ÿ† Increase app revenue using our Rules.
Apphud will automatically offer a promotional discount based subscription events.

๐Ÿ•ต๏ธ Subscription cancellation insights tool.
Understand why you customers cancel a subscription to make right product decisions.

๐Ÿ’ธ Handle billing grace period and billing issues.
Apphud will automatically ask a user to update his billing details in case of billing issue during renewal.

๐Ÿ‘ Great documentation.

๐Ÿƒโ€โ™‚๏ธ Fast support. We are online.

SDK Requirements

Apphud SDK requires minimum iOS 11.2, Xcode 10 and Swift 4.2.

Installation

Apphud SDK can be installed via CocoaPods, Swift Package Manager or manually.

Install via CocoaPods

Add the following line to your Podfile:

pod 'ApphudSDK'

In Objective-C project make sure use_frameworks! is added in your Podfile.

And then run in the Terminal:

pod install
Install via SPM (Swift Package Manager)

Add dependecy with the following URL:

https://github.com/apphud/ApphudSDK

Manual Installation

Copy all files in Source folder to your project.

Initialize Apphud SDK

To set up Apphud SDK you will need API Key. Register your app in Apphud and get your API key.

import ApphudSDK

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
	
  Apphud.start(apiKey: "YOUR_API_KEY")

  // the rest of your code
  return true
}

In Objective-C project you should import like this: #import "ApphudSDK-Swift.h"

Integrations

If you want to send subscription events to third party analytics platforms, you will need to match user IDs (in case of Amplitude or Mixpanel). The full list of available integrations is available here.

Push Notifications

To handle push notifications you need to provide Apphud with device tokens and handle incoming notifications. This 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.

Handle Subscriptions

If you have a live app and already implemented subscription purchasing, it is not necessary to rewrite your subscription purchase flow with Apphud methods. Apphud SDK will still automatically track all purchases in your app.

Apphud SDK provides a set of methods to manage subscriptions. All these methods can be used regardless how you purchased the subscription (via Apphud SDK or your existing code).

Fetch Products

Apphud automatically fetches SKProduct objects upon launch. Products identifiers must be added in our dashboard. To get your products call:

Apphud.products()

When products are fetched from the App Store you will also receive a notification from Notification Center along with Apphud delegate method call (use what fits better your needs).

Make a Purchase

To make a purchase:

Apphud.purchase(product) { result in
   // handle result
}

This method will return an ApphudPurchaseResult object, which contains subscription model with all info about your subscription. ApphudPurchaseResult may also contain transaction, error and nonRenewingPurchase objects in case user purchased non-renewing purchase. See ApphudPurchaseResult.swift and ApphudSubscription.swift files for details.

Check Subscription Status

Apphud.hasActiveSubscription()

Returns true if the user has active subscription. Use this method to determine whether or not to unlock premium functionality to the user.

Get Subscription Details

To get subscription object (which contains expiration date, autorenew status, etc.) use the following method:

Apphud.subscription()

See ApphudSubscription.swift file for details.

Check Non-renewing Purchase Status

let active = Apphud.isNonRenewingPurchaseActive(productIdentifier: "productID")

Prints true if the user has purchased in-app purchase and it's not refunded. Returns false if never purchased or refunded.

Get Non-renewing Purchase Details

To get non-renewing purchases, which contain purchase date, product identifier and cancellation date, use the following method:

Apphud.nonRenewingPurchases()

Will return array of all non-renewing in-app purchases, user has ever purchased. In-app purchases are sorted by purchase date.

Restore Purchases

If your app doesn't have a login system, which identifies a premium user by his credentials, then you need a restore mechanism. If you already have a restore purchases mechanism by calling SKPaymentQueue.default().restoreCompletedTransactions(), then you have nothing to worry about โ€“ Apphud SDK will automatically intercept and send latest App Store Receipt to Apphud servers when your restoration is completed. However, better to call our restore method from SDK:

Apphud.restorePurchases{ subscriptions, purchases, error in 
   // handle here
}

Basically it just sends App Store Receipt to Apphud and returns subscriptions in callback (or nil if nothing was ever purchased).

Migrate Existing Subscribers

If you already have a live app with paying users and you want Apphud to track their subscriptions or non-renewing purchases, you should import their App Store receipts into Apphud. Apphud SDK doesn't automatically submit App Store receipts of your existing paying users. Run this code at launch of your app:

// hasPurchases - is your own boolean value indicating that current user is paying user.
if hasPurchases {
    Apphud.migratePurchasesIfNeeded {_, _, _ in}
}

Determing Eligibility for Introductory or Promotional Offer

You can use Apphud SDK to determine if a user is eligible for an introductory or promotional offer:

// Checking eligibility for introductory offer
Apphud.checkEligibilityForIntroductoryOffer(product: myProduct) { result in
  if result {
    // User is eligible for introductory offer
  }
}

// Checking eligibility for promotional offer
Apphud.checkEligibilityForPromotionalOffer(product: myProduct) { result in
  if result {
    // User is eligible for promotional offer
  }
}

You may also check eligibility for multiple offers at one call: checkEligibilitiesForPromotionalOffers(products: [SKProduct], callback: ApphudEligibilityCallback) or checkEligibilitiesForIntroductoryOffers(products: [SKProduct], callback: ApphudEligibilityCallback)

Pricing

Apphud is absolutely free unless you make $10K per month. You can check our pricing here.

Having troubles?

If you have any questions or troubles with SDK integration feel free to contact us. We are online.

https://apphud.com/contacts

Like Apphud? Place a star at the top ๐Ÿ˜Š

Github

link
Stars: 77

Dependencies

Used By

Total: 0

Releases

0.14.2 - 2020-06-30 11:36:26

What's new in 0.14.2:

Method Apphud.startManually(apiKey: String, userID: String? = nil, deviceID: String? = nil) made public. You can override device ID. Do it for your own risk.

What's new in 0.14:

Fixed bug when consumable or nonrenewing subscription was treated as purchased, when user cancels pending payment if previously had purchases with the same product ids Added two new delegate methods to ApphudUIDelegate Minor improvements to Apphud.updateUserID(_ userID: String) method Minor improvements to [automatic / reserve ] submission of attribution params

0.14 - 2020-06-19 10:40:51

What's new in 0.14:

  • Fixed bug when consumable or nonrenewing subscription was treated as purchased, when user cancels pending payment if previously had purchases with the same product ids
  • Added two new delegate methods to ApphudUIDelegate
  • Minor improvements to Apphud.updateUserID(_ userID: String) method
  • Minor improvements to [automatic / reserve ] submission of attribution params

0.13 - 2020-06-18 15:28:25

What's new in 0.13:

  • Add two new delegate methods to ApphudUIDelegate
  • Minor improvements to Apphud.updateUserID(_ userID: String) method
  • Minor improvements to [automatic / reserve ] submission of attribution params

0.12 - 2020-05-31 08:18:50

What's new in 0.12:

  • Improved ApphudError, made it a subclass of NSError
  • startedAt property of ApphudSubscription made public
  • Better simulator detection
  • Catalyst support

0.11 - 2020-05-22 15:12:21

What's new in 0.11:

  • Automatically retries SDK initialization if couldn't do this in first try (for example, if there was no internet connection)
  • For Adjust integration: caches and resend attribution if needed

0.10 - 2020-05-12 12:57:44

What's new in 0.10: Important update for developers who use AppsFlyer SDK or Facebook SDK.

  • For users with AppsFlyer SDK integrated: automatically sends appsflyer id if developer has forgot to implement AppsFlyerTrackerDelegate methods / attribution has not arrived for some reason.
  • For users with Facebook SDK integrated: automatically sends attribution if developer has forgot to add Apphud.addAttribution(data: [ : ], from: .facebook, callback: nil) method.

0.9.6 - 2020-04-08 15:46:14

What's new in 0.9.6:

  • Automatically detect sandbox mode. New method public static func isSandbox() -> Bool is added. And old method func setIntegrationsTestMode() has been removed.
  • Improvements for Facebook Integration: if IDFA is not available, Apphud SDK collects anonymous ID to be able to send subscription events for users without IDFA. This will increase integration quality for up to 20%

0.9.4 - 2020-04-06 15:27:41

What's new in 0.9.4:

  • SDK Built with Swift 5.0. If you need Swift version less than 5.0 then use version 0.9.2.
  • Make a callback optional in func apphudShouldStartAppStoreDirectPurchase(_ product: SKProduct) -> ((ApphudPurchaseResult) -> Void)? delegate method.

0.9.3 - 2020-04-04 12:45:14

What's new in 0.9.3:

  • SDK Built with Swift 5.0. If you need Swift version less than 5.0 then use version 0.9.2.
  • Make a callback optional in func apphudShouldStartAppStoreDirectPurchase(_ product: SKProduct) -> ((ApphudPurchaseResult) -> Void)? delegate method.

0.9.1 - 2020-03-19 07:23:59

What's new in 0.9.1:

  • Fixed a bug with error property was inaccessible in ApphudPurchaseResult. Made public.
  • Added new method func pendingScreenController() -> UIViewController? which returns controller that was delayed for presentation.
  • Added new method func pendingRule() -> ApphudRule? which returns a Rule with a screen that was delayed for presentation.

See also what's new in 0.9.0 for migration guide.

0.9.0 - 2020-03-09 13:38:24

What's new in Apphud SDK 0.9.0:

  • Support for consumable, non-consumable and non-renewing subscription in-app purchases.
  • Added new Apphud delegate method func apphudNonRenewingPurchasesUpdated(_ purchases: [ApphudNonRenewingPurchase]). Called when standard in-app purchase is made or has been refunded.
  • Apple Search Ads attribution support.
  • Added new method func productsDidFetchCallback(_ callback: @escaping ([SKProduct]) -> Void). Set up a callback block when SKProducts are loaded from the App Store.
  • Added new method func refreshStoreKitProducts(_ callback: (([SKProduct]) -> Void)?) to force refresh products. Should be used only as a fallback, because Apphud SDK automatically fetched products from the App Store at launch.
  • Added new class ApphudPurchaseResult, which contains subscription, nonRenewingPurchase, transaction and error properties.
  • Changed method func purchase(_ product: SKProduct, callback: ((ApphudPurchaseResult) -> Void)?). Now it returns a new class ApphudPurchaseResult which contains all the necessary data.
  • Added new method func purchaseWithoutValidation(_ product: SKProduct, callback: ((SKPaymentTransaction, Error?) -> Void)?). This method is just a wrapper method around StoreKit, and it doesn't wait until receipt is validated. It immediately returns SKPaymentTransaction object. Use this if you don't care about validating receipts.
  • Changed method func purchasePromo(_ product: SKProduct, discountID: String, _ callback: ((ApphudPurchaseResult) -> Void)?). Now it returns a new class ApphudPurchaseResult which contains all the necessary data.
  • Method that was deprecated is now completely removed func submitReceipt(_ productIdentifier : String, _ callback : ((ApphudSubscription?, Error?) -> Void)?). Apphud SDK automatically submits App Store receipts to Apphud.
  • Added new method func nonRenewingPurchases() -> [ApphudNonRenewingPurchase]? which returns array of standard in-app purchases, if there are any.
  • Added new class ApphudNonRenewingPurchase which contains product identifier, purchase date and and optional cancellation date.
  • Added new method func isNonRenewingPurchaseActive(productIdentifier : String) -> Bool. Returns true if current user has purchased standard in-app purchase with given product identifier. Returns false if this product is refunded or never purchased.
  • Method restoreSubscriptions renamed to func restorePurchases(callback: @escaping ([ApphudSubscription]?, [ApphudNonRenewingPurchase]?, Error?) -> Void). Added new callback parameter [ApphudNonRenewingPurchase]?, which returns array of standard in-app purchases, if there are any.
  • Method migrateSubscriptionsIfNeeded renamed to func migratePurchasesIfNeeded(callback: @escaping ([ApphudSubscription]?, [ApphudNonRenewingPurchase]?, Error?) -> Void). Added new callback parameter [ApphudNonRenewingPurchase]?, which returns array of standard in-app purchases, if there are any.
  • Added new method func setFinishAllTransactions(). Using this method Apphud SDK will finish all pending transactions, not only those that were started by Apphud SDK. See Apphud.swift for details.
  • Apphud SDK now tries to re-register user, re-fetch products and re-submit receipts when application becomes active if there were errors on app launch; for example, if there was no Internet connection.

Migration guide to 0.9.0:

  • Update pod using terminal: pod update ApphudSDK
  • Update method from Apphud.purchase(product) { (subsription, error) in ...} to Apphud.purchase(product) { result in ...}. You will find subscription and error objects inside new ApphudPurchaseResult object.
  • Update method from Apphud.purchasePromo(product, discountID: promoID) { (subsription, error) in ...} to Apphud.purchasePromo(product, discountID: promoID) { result in ...}. You will find subscription and error objects inside new ApphudPurchaseResult object.
  • Update method from Apphud.restoreSubscriptions { subscriptions, error in ...} to Apphud.restorePurchases { subscriptions, purchases, error in ...}.
  • Update method from Apphud.migrateSubscriptionsIfNeeded { subscriptions in ...} to Apphud.migratePurchasesIfNeeded { subscriptions, purchases, error in ...}.

0.8.5 - 2020-02-14 12:10:47

What's new in 0.8.5:

  • Added new ApphudUIDelegate method func apphudShouldPerformRule(rule: ApphudRule) -> Bool. See Apphud.swift for method explanation.
  • (Attention!) Renamed ApphudUIDelegate method to func apphudShouldShowScreen(screenName: String) -> Bool. Don't forget to update this method parameter, if you were using it.
  • Added Adjust support.
  • Renamed func restoreSubscriptions(callback: @escaping ([ApphudSubscription]?, Error?) -> Void). Added Error? parameter.
  • Improved logic for func migrateSubscriptionsIfNeeded method.
  • Pretty printed logs.
  • Fixed bug with user id being changed sometimes.
  • User ID is now saved to Keychain, so after re-install it is restored.
  • Fixed bug with push opened event not being sent in some cases.
  • Add rule name and screen name to delegate methods.
  • Add more logs.

0.8 - 2020-01-05 08:07:49

What's new in 0.8:

  • New Rules support. Old rules (win back lapsed subscribers, billing issue) are deprecated and no longer supported since this SDK version. When upgrading to this SDK version, you should create your new screens and rules in web dashboard. If you need help with SDK upgrade, please contact us: https://apphud.com/contacts
  • Method func submitReceipt(_ productIdentifier : String, _ callback : ((ApphudSubscription?, Error?) -> Void)?) is now deprecated. You don't need to call it anymore, as starting now Apphud SDK automatically tracks all your in-app purchases and submits App Store receipt to Apphud. If you were using callback from this method, you can use apphudSubscriptionsUpdated delegate method instead;
  • Added new protocol ApphudUIDelegate with screen controller delegate methods;
  • Delete method func apphudScreenPresentationStyle(controller: UIViewController) -> UIModalPresentationStyle is moved from ApphudDelegate to new protocol ApphudUIDelegate;
  • Added new method func showPendingScreen() to present Apphud screen that was delayed (i.e. returned false) in apphudShouldShowScreen delegate method;
  • Added new method func migrateSubscriptionsIfNeeded(callback: @escaping ([ApphudSubscription]?) -> Void) which helps you to migrate existing subscribers into Apphud. Useful when adding Apphud SDK to live app.
  • Other minor bug fixes and improvements.

0.7.5 - 2019-10-31 17:03:31

What's new in 0.7.5:

  • Added new method func disableIDFACollection() to disable IDFA collection. Method must be called before SDK initialization.
  • Downgraded minimum required Swift version from 5.0 to 4.2.
  • Added protection from calling initialization method twice.

0.7.4 - 2019-10-16 10:07:37

What's new in 0.7.4:

  • Added new method func setIntegrationsTestMode(). If this method is called, Apphud will send all subscription events of current user to your test analytics, if test api keys are set in integrations dashboard.
  • Improved SDK initialization logic

0.7.3 - 2019-10-04 10:32:01

What's new in 0.7.3:

  • Added new method func addAttribution(data: [AnyHashable : Any], from provider: ApphudAttributionProvider, identifer: String? = nil, callback: ApphudBoolCallback?). Use this method to submit attribution data from your attribution provider.
  • Added new method func didFetchProductsNotification() -> Notification.Name. Add observer to this notification name to get notified when SKProducts are fetched from StoreKit.
  • Added new method func products() -> [SKProduct]?. Returns array of SKProduct objects fetched from StoreKit. Now you don't have to fetch and store products for yourself.
  • Callback in func submitPushNotificationsToken(token: Data, callback: ApphudBoolCallback?) method is now optional.
  • Method func purchase(product: SKProduct, callback: ((ApphudSubscription?, Error?) -> Void)?) renamed to more lightweight func purchase(_ product: SKProduct, callback: ((ApphudSubscription?, Error?) -> Void)?).

0.6.8 - 2019-09-26 13:37:31

What's new in 0.6.8:

  • Fixed a bug when in dark mode in iOS 13 feedback screen had black text view (should be always white)

0.6.7 - 2019-09-26 12:38:13

What's new in 0.6.7:

  • Added loader in Apphud purchase screen

0.6.5 - 2019-09-25 14:21:16

What's new in Apphud SDK 0.6.5

  • Added func apphudScreenPresentationStyle() -> UIModalPresentationStyledelegate method to make control presentation style of Apphud controller. This is useful since iOS 13 presents in page sheet style by default. Now you can make it full screen.
  • Added two more delegate methods that help to control present/dismiss actions of Apphud controller
  • Improved apphudSubscriptionsUpdated delegate method. Updated documentation.

- 2019-09-24 07:52:19

What's new in Apphud SDK 0.6.3

  • Added a callback to restore subscriptions method: Apphud.restoreSubscriptions(callback: @escaping ([ApphudSubscription]?) -> Void)
  • Method Apphud.purchasedSubscription() renamed to Apphud.subscription() to avoid misleading.
  • Method Apphud.purchasedSubscriptions() renamed to Apphud.subscriptions() to avoid misleading.
  • Added new Apphud.hasActiveSubscription()-> Bool method which returns boolean value. Use this method to determine whether or not to unlock premium functionality to the user.
  • Added new delegate method apphudDidFetchStoreKitProducts(_ products: [SKProduct]) which returns array of StoreKit products that you added in Apphud. Now you don't need to fetch products from StoreKit for yourself.
  • Documentation in many SDK methods has been improved to avoid misleading.