Share
Explore

Shinara Swift SDK

Shinara is a mobile-first social referral platform tailored for in-app purchases, empowering brands to grow through influencer-driven advocacy. The Swift SDK enables seamless integration of Shinara's referral and attribution system into your iOS applications.
Website:

Overview

Install the SDK
During onboarding, add a referral code screen to ask user to input their referral code
Integrate Shinara SDK methods to your App’s Lifecycle

Shinara SDK in your App’s Lifecycle

Untitled Diagram.drawio (2).png

Installation

Installation is available via Swift Package Manager
In Xcode:
Navigate to File > Add Package Dependency
Click "Add Package"

Dependencies

Foundation
Alamofire

Usage

Initialization

Initialize the SDK at app launch, typically in your AppDelegate or main view controller:
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
ShinaraSDK.instance.initialize(apiKey: "<YOUR_API_KEY>") { result in
switch result {
case .success:
print("Shinara SDK initialized successfully")
case .failure(let error):
print("Shinara SDK initialization failed")
}
}
return true
}
}

Referral Code Validation

To validate a referral code, use the validateReferralCode method. This method checks the validity of the given code.
Note: Ensure that the referral code is validated before initiating an In-App Purchase. This is crucial for proper attribution of the purchase to the referral code in the Shinara SDK.
ShinaraSDK.instance.validateReferralCode(code: referralCode) { result in
switch result {
case .success(let programId):
// Valid referral code
// programId can be used to map and apply discounts
print("Valid referral code with program ID: \(programId)")
case .failure(let error):
// Invalid referral code or error occurred
print("Validation failed: \(error.localizedDescription)")
}
}

Attribute Purchase

To attribute a purchase made by affiliates, use the attributePurchase method. Call this method after a successful in app purchase.
let productId: String = transaction.payment.productIdentifier // in app purchase product from storekit transaction
let transactionId: String = transaction.transactionIdentifier ?? "" // in app purchase transaction id from storekit transaction
ShinaraSDK.instance.attributePurchase(productId: productId, transactionId: transactionId) { result in
switch result {
case .success(_):
// handle success
case .failure(let error):
// handle error
}
}

User Registration (Optional)

By default, Shinara generates a new user id and attribute to the purchase. Optionally, you can provide your own userId and other user details to make sure attribution of the purchase has the user id of your choice.
Note: Ensure that the referral code is validated before registering a user. This is crucial for proper attribution of the user to the referral code in the Shinara SDK.
ShinaraSDK.instance.registerUser(
userId: "YOUR_INTERNAL_USER_ID",
email: "user@example.com", // Optional
name: "John Doe", // Optional
phone: "+1234567890" // Optional
) { result in
switch result {
case .success:
print("User registered successfully")
case .failure(let error):
print("Registration failed: \(error.localizedDescription)")
}
}

Example App


Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.