Swiftpack.co - Package - apphud/ApphudSDK
Apphud

Apphud SDK

Apphud SDK is a lightweight open-source Swift library to manage auto-renewable subscriptions 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.

๐Ÿ” 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 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

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) { (subscription, error) in
   // handle result
}

This method will return a subscription model, which contains all relevant info about your subscription, including expiration date. See ApphudSubscription.swift file 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.

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.restoreSubscriptions{ subscriptions 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, you should import their App Store receipts into Apphud. Apphud SDK doesn't automatically submit App Store receipts of your existing subscribers. Run this code at launch of your app:

// hasPurchases - is your own boolean value indicating that current user is paying user.
if hasPurchases {
    Apphud.migrateSubscriptionsIfNeeded {_ 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: 63

Dependencies

Used By

Total: 0

Releases

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.