此 NimbleLoyalty SDK 库允许开发者轻松地将忠诚度计划集成到他们的 iOS 应用程序中。

功能

组件库

要求

安装

iOS Loyalty SDK 可以使用 CocoaPods 或 Swift Package Manager 安装。

CocoaPods

要使用 CocoaPods 安装,请将以下行添加到您的 Podfile

pod 'NimbleLoyalty', '~> 0.1.0'

Swift Package Manager

要使用 Swift Package Manager 安装,请将以下行添加到您的依赖项

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

使用

身份验证

在验证用户身份之前,请务必设置 clientIdclientSecret

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

检查用户是否已通过身份验证。

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

启动身份验证流程。

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()

移除会话,有效地注销用户。

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

获取奖励列表

检索已验证用户的可用奖励列表。

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

获取奖励详情

检索特定奖励的详细信息。

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

兑换奖励

使用给定的奖励代码为已验证用户兑换奖励。

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

获取奖励历史记录

检索已验证用户的奖励历史记录。

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

获取产品列表

检索已验证用户的可用产品列表。

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

获取产品详情

检索特定产品的详细信息。

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

示例

  1. 导航到 Example 文件夹。
  2. 在 .env.example 中填写环境值并将其重命名为 .env
  3. 运行 bundle install
  4. 运行 bundle exec arkana
  5. 运行 bundle exec pod install
  6. 打开 Example.xcworkspace。
  7. 构建并运行项目。

示例


展示 SDK 功能的主屏幕

• 登录
• 奖励列表
• 奖励历史记录


Home


奖励列表屏幕,显示奖励信息。

• 图像
• 标题和描述
• 到期时间
• 奖励兑换


RewardList


奖励详情屏幕,显示奖励信息。

• 图像
• 标题和描述
• 到期时间
• 奖励兑换
• 条款


RewardDetails


奖励历史记录屏幕,显示已兑换的奖励信息。

• 图像
• 标题
• 到期时间


RewardHistory


产品列表屏幕,显示产品信息。

• 图像
• 标题和描述


ProductList


产品详情屏幕,显示产品信息。

• 图像
• 标题和描述


ProductDetails

鸣谢

Nimble logo

此项目由 Nimble 维护和资助。

许可证

此项目版权归 Nimble 所有,始于 2023 年。它是自由软件,可以根据 LICENSE 文件中指定的条款进行重新分发。