Provider Initialisation
Provider minimum requirement
You provide recipes and use Mealz to push it to a retailer. For example, a food delivery service that works with multiple grocery stores.
ProviderKey - base64 key to set information
This will be provided by Mealz during implementation. This will include information such as PROD vs UAT & your unique company identifier.
If you just want to play around, you can use the sample Mealz Store:
let providerKey = "ewoJInByb3ZpZGVyX2lkIjogIjE0IiwKCSJwbGF1c2libGVfZG9tYWluZSI6ICJtaWFtLnRlc3QiLAoJIm1pYW1fb3JpZ2luIjogIm1pYW0iLAoJIm9yaWdpbiI6ICJtaWFtIiwKCSJtaWFtX2Vudmlyb25tZW50IjogIlVBVCIKfQ"
which you'll see decodes from base 64 to this:
{
"provider_id": "14",
"plausible_domaine": "miam.test",
"miam_origin": "miam",
"origin": "miam",
"miam_environment": "UAT"
}
Your keys will be provided by our Development team
Basic implementation
There are several options to configure to handle authless users. The below is a basic implementation where the Mealz initialization process will only start after the user is logged in and has selected a valid store.
First, to init Mealz we need your application context and your provider key
Two keys will have been sent to you: one for development and one for production.
public class MealzManager: ObservableObject {
public static let sharedInstance = MealzManager()
private init() {
Mealz.shared.Core(init: { coreBuilder in
// set supplier key
coreBuilder.sdkRequirement(init: { requirementBuilder in
requirementBuilder.key = self.supplierKey
})
})
}
}
User setup
Here is how to pass the user ID to the SDK, directly within the host app:
You can also enable our authless feature, more information here.
// From anywhere
import mealzcore
// existingUserId is your user id, type String is expected
Mealz.shared.user.updateUserId(userId: existingUserId, authorization: Authorization.userId)
Here is how to inform the SDK whenever the user login state changes. We recommend using Observables or EventListeners to that end.
// file MealzManager.swift
import mealzcore
public class MealzManager {
// CODE
private init() {
// CODE
OBSERVABLE_ON_USER_OBJECT.sink { _ in
// existingUserId is your user id, type String is expected
Mealz.shared.user.updateUserId(userId: existingUserId, authorization: Authorization.userId)
}
}
// CODE
}
To get full list of user features check User configurations.
Store setup
For Mealz to work properly, your user must be connected to a specific store so we can accurately provide recipes with available ingredients. To add the store that the user is currently at, you can use this code:
import mealzcore
// STORE_ID_IN_HOST_APP is your store id, type String is expected
Mealz.shared.user.setStoreWithMealzIdWithCallBack(storeId: STORE_ID_IN_HOST_APP) { _ in /** action to execute one mealz store has been fetch and set can be a redirection */}
You can also set a callback to redirect to your Store Selector, more information here.
Congratulations, Mealz is good to go 🥳