An easy to use framework for building iOS apps for the open food facts api. More features will be added soon this is just an initial start...
Install using cocoapods
pod 'OpenFoodFactsSDK', :git => 'https://github.com/keegho/off-sdk-ios.git'
Install using carthage
Install Homebrew
$ brew update
$ brew install carthage
Create Cartfile in your project root folder and add this to it.
github "keegho/off-sdk-ios"
Then in your terminal project root folder type.
carthage update
Now make sure to drag-and-drop the built frameworks into your Xcode project and import them in the source files that require them.
Example Read:
import OpenFoodFactsSDK
//In the AppDelegate.swift setup your enviroment and url prefix
private let off = OFF()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
off.enviroment = .production //.production . testing //Default production
off.lanugageUrl = .fr //.world .fr .ar .de //Default world
return true
}
//Then in the ViewController
import OpenFoodFactsSDK
private let off = OFF()
private var item = OFFProduct()
override func viewDidLoad() {
super.viewDidLoad()
//Call get product closure function
off.getProduct(code: "737628064502") { (product, message) in
if product != nil {
item = product!
print(item?.genericName ?? "NO PRODUCT NAME")
} else {
print(message ?? "NO MESSAGE")
}
}
}
Example Write:
import OpenFoodFactsSDK
//In the AppDelegate.swift setup your enviroment and url prefix
private let off = OFF()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
off.enviroment = .production //.production . testing //Default production
off.lanugageUrl = .fr //.world .fr .ar .de //Default world
off.username = "foo" // username needed when editing
off.password = "bar" // password needed when editing
return true
}
//Then in the ViewController
import OpenFoodFactsSDK
private let off = OFF()
private var item = OFFProduct()
override func viewDidLoad() {
super.viewDidLoad()
item.code = "1"
item.genericName = "Golden Virginia Tobacco"
item.productName = "Golden Virginia Classic"
item.brandsText = "Golden Viginia"
item.labelsText = "Causes Death, Die young"
item.quantity = "50g"
//Call add product closure function
off.addProduct(product: item) { (status, msg) in
switch status {
case .success:
print("ADDED")
case .failure:
print("NOT ADDED")
}
}
}