I have a problem in my code the self.navigationController.pushViewController
function is being called infinite time, my code is attached, I am getting a product information by reading its barcode.
More details:More details: More details: More details:More details:
func captureOutput(captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [AnyObject]!, fromConnection connection: AVCaptureConnection!) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let nav = storyboard.instantiateViewControllerWithIdentifier("companyInfoNAv") as! UINavigationController
let companyInfoView = nav.topViewController as! CompanyInformationViewController // toggleFlash()
for meta_Data in metadataObjects {
let decoded_data: AVMetadataMachineReadableCodeObject = meta_Data as! AVMetadataMachineReadableCodeObject
self.output_Label.text = decoded_data.stringValue
self.reader_Type.text = decoded_data.type
let manager: AFHTTPSessionManager = AFHTTPSessionManager.init()
manager.GET("https://api.outpan.com/v2/products/"+decoded_data.stringValue+"?apikey="+"944b2810f5072d9d125f5fcf32543r1", parameters: nil, success: { (NSURLSessionDataTask, responseObject) in
self.arrayObjects = responseObject as! NSDictionary
print(self.arrayObjects)
if(( self.arrayObjects.objectForKey("name")?.empty) == nil){
let attributes : NSDictionary!
attributes = self.arrayObjects.objectForKey("attributes") as! NSDictionary
if(attributes.count > 3){
if(attributes.objectForKey("Manufacturer")?.empty == nil){
companyInfoView.companyName = attributes.objectForKey("Manufacturer") as! NSString as String
}
}else{
companyInfoView.companyName = "No Name in DATABASE"
}
}
else{
companyInfoView.companyName = "No Name in DATABASE"
}
print(self.arrayObjects.objectForKey("name"))
}, failure: { (operation, error) in
print(error)
})
}
self.navigationController?.pushViewController(companyInfoView, animated: true)
}
your API manager is executing asynchronously, you should push the navigation controller
inside the success
block as below, or using completion
manager.GET("https://api.outpan.com/v2/products/"+decoded_data.stringValue+"?apikey="+"944b2810f5072d9d125f5fc1217855f1", parameters: nil, success: { (NSURLSessionDataTask, responseObject) in
self.arrayObjects = responseObject as! NSDictionary
print(self.arrayObjects)
if(( self.arrayObjects.objectForKey("name")?.empty) == nil){
let attributes : NSDictionary!
attributes = self.arrayObjects.objectForKey("attributes") as! NSDictionary
if(attributes.count > 3){
if(attributes.objectForKey("Manufacturer")?.empty == nil){
companyInfoView.companyName = attributes.objectForKey("Manufacturer") as! NSString as String
}
}else{
companyInfoView.companyName = "No Name in DATABASE"
}
}
else{
companyInfoView.companyName = "No Name in DATABASE"
}
print(self.arrayObjects.objectForKey("name"))
// push the navigation controller here
self.navigationController?.pushViewController(companyInfoView, animated: true)
}, failure: { (operation, error) in
print(error)
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.