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.

Installation

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

Dependencies

Foundation
StoreKit
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)")
}
}

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)")
}
}

Purchase Tracking

The SDK automatically tracks and attributes in-app purchases. No additional code is required for basic purchase tracking. The SDK listens to StoreKit transactions and handles attribution automatically.

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.