Закончено выполнение рабочего процесса. Если он не подключен, удалите и повторите попытку. Спасибо Kuba
if (barcodeLength == 13) {
// EAN-13 \\
// ********** Database Function ********** Database Function ********** \\
// 1
let urlString: String = "http://\(hostString):\(portString)/barcode.php?&password=\(passString)&db=\(dbString)&barNum=\(self.scannedBarcode)"
let url: NSURL? = NSURL(string: urlString)!
let urlSession = NSURLSession.sharedSession()
//2
let jsonQuery = urlSession.dataTaskWithURL(url!, completionHandler: { data, response, error -> Void in
if (error != nil) {
println("\(error.localizedDescription)")
}
var err: NSError?
var jsonResult: Array? = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &err) as NSArray?
if (err != nil) {
println("Can't connect using credentials")
println("JSON Error \(err!.localizedDescription)")
}
if jsonResult?.count == 0 {
println("Check digit removed from EAN-13")
self.scannedBarcode.removeAtIndex(self.scannedBarcode.endIndex.predecessor())
println(self.scannedBarcode)
self.jsonComp()
return
}
println("Well, this is 13 digit EAN-13")
// 4
let itemID: String! = jsonResult![0]["ITEM_ID"] as NSString
let itemName: String! = jsonResult![0]["ITEM_Kitchen_Name"] as NSString
let itemPrice: String! = jsonResult![0]["ITEM_Sale_Price"] as NSString
println(itemID, itemName, itemPrice)
self.selectedID = itemID
self.selectedName = itemName
self.selectedPrice = itemPrice
dispatch_async(dispatch_get_main_queue(), {
self.performSegueWithIdentifier("editPrice", sender: AnyObject?())
//
})
})
// 5
jsonQuery.resume()
}
else if (barcodeLength == 12) {
// UPC-A \\
// ********** Database Function ********** Database Function ********** \\
// 1
let urlString: String = "http://\(hostString):\(portString)/barcode.php?&password=\(passString)&db=\(dbString)&barNum=\(self.scannedBarcode)"
let url: NSURL? = NSURL(string: urlString)!
let urlSession = NSURLSession.sharedSession()
//2
let jsonQuery = urlSession.dataTaskWithURL(url!, completionHandler: { data, response, error -> Void in
if (error != nil) {
println("\(error.localizedDescription)")
}
var err: NSError?
var jsonResult: Array? = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &err) as NSArray?
if (err != nil) {
println("Can't connect using credentials")
println("JSON Error \(err!.localizedDescription)")
}
if jsonResult?.count == 0 {
println("Check digit removed from UPC-A")
self.scannedBarcode.removeAtIndex(self.scannedBarcode.endIndex.predecessor())
println(self.scannedBarcode)
self.jsonComp()
return
}
println("Well, this is 12 digit UPC-A")
// 4
let itemID: String! = jsonResult![0]["ITEM_ID"] as NSString
let itemName: String! = jsonResult![0]["ITEM_Kitchen_Name"] as NSString
let itemPrice: String! = jsonResult![0]["ITEM_Sale_Price"] as NSString
println(itemID, itemName, itemPrice)
self.selectedID = itemID
self.selectedName = itemName
self.selectedPrice = itemPrice
dispatch_async(dispatch_get_main_queue(), {
self.performSegueWithIdentifier("editPrice", sender: AnyObject?())
//
})
})
// 5
jsonQuery.resume()
}
else if (barcodeLength == 8) {
// ********** Database Function ********** Database Function ********** \\
// 1
let urlString: String = "http://\(hostString):\(portString)/barcode.php?&password=\(passString)&db=\(dbString)&barNum=\(self.scannedBarcode)"
let url: NSURL? = NSURL(string: urlString)!
let urlSession = NSURLSession.sharedSession()
//2
let jsonQuery = urlSession.dataTaskWithURL(url!, completionHandler: { data, response, error -> Void in
if (error != nil) {
println("\(error.localizedDescription)")
}
var err: NSError?
var jsonResult: Array? = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &err) as NSArray?
if (err != nil) {
println("Can't connect using credentials")
println("JSON Error \(err!.localizedDescription)")
}
if jsonResult?.count == 0 {
println("Well, this is UPC-E")
self.scannedBarcode.removeAtIndex(self.scannedBarcode.startIndex)
self.scannedBarcode.removeAtIndex(self.scannedBarcode.endIndex.predecessor())
println(self.scannedBarcode)
self.jsonComp()
return
}
println("Well, this is EAN-8")
// 4
let itemID: String! = jsonResult![0]["ITEM_ID"] as NSString
let itemName: String! = jsonResult![0]["ITEM_Kitchen_Name"] as NSString
if jsonResult![0]["ITEM_Sale_Price"] == nil {
println("No Sale Price")
dispatch_async(dispatch_get_main_queue(), {
HUDController.sharedController.hide(afterDelay: 0.1)
})
var refreshAlert = UIAlertController(title: "Camaleon Reports", message: "Barcode does not have a price set", preferredStyle: UIAlertControllerStyle.Alert)
refreshAlert.addAction(UIAlertAction(title: "Retry", style: .Default, handler: { (action: UIAlertAction!) in
println("Yes Logic")
}))
self.presentViewController(refreshAlert, animated: true, completion: nil)
return
}
let itemPrice: String! = jsonResult![0]["ITEM_Sale_Price"] as NSString
println(itemID, itemName, itemPrice)
self.selectedID = itemID
self.selectedName = itemName
self.selectedPrice = itemPrice
dispatch_async(dispatch_get_main_queue(), {
self.performSegueWithIdentifier("editPrice", sender: AnyObject?())
//
})
})
// 5
jsonQuery.resume()
} else {
dispatch_async(dispatch_get_main_queue(), {
HUDController.sharedController.hide(afterDelay: 0.1)
})
var refreshAlert = UIAlertController(title: "Camaleon Reports", message: "Barcode does not exist", preferredStyle: UIAlertControllerStyle.Alert)
refreshAlert.addAction(UIAlertAction(title: "Retry", style: .Default, handler: { (action: UIAlertAction!) in
println("Yes Logic")
}))
self.presentViewController(refreshAlert, animated: true, completion: nil)
return
}
}
Какую библиотеку/API вы используете для чтения штрих-кодов? –