目录
目录README.md

This NimbleLoyalty SDK library allows developers to easily integrate loyalty programs into their iOS applications.

Features

  • Authenticate
  • Get reward list
  • Get reward detail
  • Redeem reward
  • Get reward history
  • Get product list
  • Get product detail

Component Libraries

  • Moya
  • KeychainAccess

Requirements

  • iOS 14.0+
  • Xcode 14.0+

Installation

The iOS Loyalty SDK can be installed using CocoaPods or Swift Package Manager.

CocoaPods

To install using CocoaPods, add the following line to your Podfile:

pod 'NimbleLoyalty', '~> 0.1.0'

Swift Package Manager

To install using Swift Package Manager, add the following line to your dependencies:

.package(url: "https://github.com/nimblehq/business-loyalty-ios-sdk-poc.git", from: "0.1.0")

Usage

Authentication

Before authenticating the user, remember to set the clientId and clientSecret.

NimbleLoyalty.shared.setClientId("CLIENT_ID")
NimbleLoyalty.shared.setClientSecret("CLIENT_SECRET")
isAuthenticated()

Checks if the user is authenticated.

if NimbleLoyalty.shared.isAuthenticated() {
    // The user is authenticated, do something
} else {
    // The user is not authenticated, show a login button
}
authenticate(completion:)

Initiates the authentication flow.

NimbleLoyalty.shared.authenticate { result in
    switch result {
    case .success:
        // The user is authenticated, do something
    case .failure(let error):
        print("Error authenticating: \(error.localizedDescription)")
    }
}
clearSession()

Remove the session, effectively logging the user out.

// Clear the user's session
NimbleLoyalty.shared.clearSession()

Get Reward List

Retrieves the list of available rewards for the authenticated user.

NimbleLoyalty.shared.getRewardList { result in
   switch result {
   case .success(let rewardList):
       // Display the list of rewards to the user
       for reward in rewardList.rewards {
           print("Reward name: \(reward.name)")
       }
   case .failure(let error):
       print("Error retrieving rewards: \(error.localizedDescription)")
   }
}

Get Reward Detail

Retrieves the detail of a specific reward.

NimbleLoyalty.shared.getRewardDetail(code: "reward_id") { result in
   switch result {
   case .success(let rewardDetail):
       // Display the reward detail to the user
   case .failure(let error):
       print("Error retrieving reward detail: \(error.localizedDescription)")
   }
}

Redeem a Reward

Redeems a reward with the given reward’s code for the authenticated user.

NimbleLoyalty.shared.redeemReward(code: "ABC123") { result in
   switch result {
   case .success(let rewardList):
       print("Reward redeemed with ID: \(redeemReward.id)")
   case .failure(let error):
       print("Error redeeming reward: \(error.localizedDescription)")
   }
}

Get Reward History

Retrieves the reward history for the authenticated user.

NimbleLoyalty.shared.getRewardHistory { result in
   switch result {
   case .success(let rewardHistory):
       // Display the reward history to the user
       for reward in rewardHistory {
           print("Reward name: \(reward.name)")
       }
   case .failure(let error):
       print("Error retrieving reward history: \(error.localizedDescription)")
   }
}

Get Product List

Retrieves the list of available products for the authenticated user.

NimbleLoyalty.shared.getProductList { result in
   switch result {
   case .success(let products):
       // Display the list of products to the user
       for product in products {
           print("Product name: \(product.name)")
       }
   case .failure(let error):
       print("Error retrieving products: \(error.localizedDescription)")
   }
}

Get Product Detail

Retrieves the detail of a specific product.

NimbleLoyalty.shared.getProductDetail(id: "product_id") { result in
   switch result {
   case .success(let productDetail):
       // Display the reward detail to the user
   case .failure(let error):
       print("Error retrieving reward detail: \(error.localizedDescription)")
   }
}

Samples

  1. Navigate to the Example folder.
  2. Fill environment values in .env.example and rename it to .env
  3. Run bundle install
  4. Run bundle exec arkana
  5. Run bundle exec pod install.
  6. Open Example.xcworkspace.
  7. Build and run the project.

Example


Home screen that demonstrate features from SDK

• Sign-in
• Reward List
• Reward History


Home


Reward List screen that show reward information.

• Image
• Title & description
• Expiration
• Reward redemption


RewardList


Reward Details screen that show reward information.

• Image
• Title & description
• Expiration
• Reward redemption
• Terms


RewardDetails


Reward History screen that show redeemed reward information.

• Image
• Title
• Expiration


RewardHistory


Product List screen that show product information.

• Image
• Title & description


ProductList


Product Details screen that shows product information.

• Image
• Title & description


ProductDetails

Credits

Nimble logo

This project is maintained and funded by Nimble.

License

This project is Copyright (c) 2023 and onwards Nimble. It is free software and may be redistributed under the terms specified in the LICENSE file.

关于
7.6 MB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号