openfoodfacts / openfoodfacts-swift

The idea is to create a Swift SDK (possibly leveraging our OpenAPI support https://openfoodfacts.github.io/openfoodfacts-server/api/, or our legacy iOS app https://github.com/openfoodfacts/openfoodfacts-ios)
Apache License 2.0
19 stars 9 forks source link
hacktoberfest nutrition sdk-swift swift

openfoodfacts-swift

Open Food Facts - Swift

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.

Compatibility

iOS 15+, verified compatibility only with Swift 5.9 for now

Prerequisits

For adding product's pictures the SDK uses camera and gallery. App which integrates it should add NSCameraUsageDescription and NSPhotoLibraryUsageDescription.

How to use ?

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

}

Submit new

Screenshot1 Screenshot2 Screenshot3 Screenshot4

View existing

Screenshot5 Screenshot6 Screenshot7

Edit mode is in progress

Open Food Facts config

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)

Notes

You may skip the following parameters in case of:

  1. For staging environment default user if off/off
  2. UserAgent is autogenerated using plist env properties like CFBundleName/CFBundleShortVersionString/CFBundleVersion and device's UUID

Third party dependencies

See NOTICE with all dependencies of OpenFoodFactsSDK and their licensing

General principles

Contributing

If your users do not expect a specific result immediately (eg. Inventory apps)

If your users do expect a result immediately (eg Nutrition apps, Scoring apps…):

Open Data Licence

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.

Applications using this SDK

If you use this SDK, Feel free to open a PR to add your application in this list.

Authors

Contributors

Drag Racing