This NimbleLoyalty SDK library allows developers to easily integrate loyalty programs into their iOS applications.
- Authenticate
- Get reward list
- Get reward detail
- Redeem reward
- Get reward history
- Moya
- KeychainAccess
- iOS 14.0+
- Xcode 14.0+
The iOS Loyalty SDK can be installed using CocoaPods or Swift Package Manager.
To install using CocoaPods, add the following line to your Podfile:
pod 'NimbleLoyalty', '~> 0.1.0'
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")
Before authenticating the user, remember to set the clientId and clientSecret.
NimbleLoyalty.shared.setClientId("CLIENT_ID")
NimbleLoyalty.shared.setClientSecret("CLIENT_SECRET")
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
}
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)")
}
}
Remove the session, effectively logging the user out.
// Clear the user's session
NimbleLoyalty.shared.clearSession()
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)")
}
}
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)")
}
}
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)")
}
}
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)")
}
}
This project is maintained and funded by Nimble.
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.