Swift package for the Open Food Facts API. Easily access to more than 1.9 million products from all around the world. Open Food Facts is powered by contributors from around the world and is constantly growing thanks to them.
iOS 15+, verified compatibility only with Swift 5.9 for now
For adding product's pictures the SDK uses camera and gallery. App which integrates it should add NSCameraUsageDescription and NSPhotoLibraryUsageDescription.
See ExampleApp
for two scenarious of starting screen from scanning product or entering it manually
You can integrate the SDK into your iOS app using SPM (Swift Package Manager) by searching the repo using github's url
There are two modes for now: new and view
Sample codes: existing 5900102025473 [pl] / 8711258029584 [nl], missing 5701377101134 [pl]
SDK has screen to view or submit product (in OFF's Product json "scheme")
ProductPage(barcode: barcode) { uploadedProduct in
}
Edit mode is in progress
All available settings are in class OFFConfig
. Set them in your AppDelegate
method didFinishLaunchingWithOptions
OFFConfig.shared.useRequired = false
OFFConfig.shared.apiEnv = .staging
OFFConfig.shared.country = OpenFoodFactsCountry.POLAND
OFFConfig.shared.productsLanguage = OpenFoodFactsLanguage.DUTCH
OFFConfig.shared.userAgent = UserAgent(name: "AgentName", version: "1.0", system: "iOS", comment: "Some comment")
OFFConfig.shared.globalUser = User(userId: "<YOUR_USERNAME>", password: "<PASSWORD>")
.useRequired
- this flag indicates bare minimum about product, its photos and nutriments (In Progress). It makes base validation for you and shows missing by user fields before sending product, set to false to ommit any validation
.apiEnv
- .staging/.production
switch between testing environment world.openfoodfacts.net
and production world.openfoodfacts.org
.productsLanguage
- you can present product's language if you know it, although editor has picker for it
country
- you can preset country (In progress)
Autogenerated or use your own description of user agent if you want to personalise instance of app which make READ/WRITE requests to API
OFFConfig.shared.UserAgent(name: "AgentName", version: "1.0", system: "iOS", comment: "Some comment")
Production environment requires user created at world.openfoodfacts.org
, staging uses off/off
OFFConfig.shared.globalUser = User(userId: "<YOUR_USERNAME>", password: "<PASSWORD>")
Editor/Viewer for barcode
ProductPage(barcode: self.$barcode, isPresented: self.$isProductEditorPresent, submitProduct: $submitProduct)
You may skip the following parameters in case of:
off/off
CFBundleName/CFBundleShortVersionString/CFBundleVersion
and device's UUIDSee NOTICE with all dependencies of OpenFoodFactsSDK and their licensing
The database in under the OdBL. This means attributing the source and also contributing back any additions (photos, data), which this package makes easy to do. You can check the terms of use here : Terms of use.
If you use this SDK, Feel free to open a PR to add your application in this list.