What can cause addAttachment to never call its completion block?
func addImage(_ image: UIImage, toFeature agsArcGISFeature: AGSArcGISFeature, completion: @escaping ((Error?) -> Void)) {
agsArcGISFeature.load() { error in
if let error = error {
completion(error)
return
}
guard let imageData = image.jpegData(compressionQuality: 0.85) else {
completion(nil)
return
}
print("Calling addAttachment()")
agsArcGISFeature.addAttachment(withName: "image.jpg", contentType: "jpg", data: imageData) { agsAttachment, error in
if let error = error {
print("addAttachment() completed with error")
completion(error)
} else {
print("addAttachment() completed successfully")
completion(nil)
}
}
}
}
In the above code, neither of the print() statements (lines 16 or 19) ever execute. The feature is a loaded feature from a feature service in ArcGIS Online. I feel like I am missing something simple.
Solved! Go to Solution.
I suspect, agsArcGISFeature is getting released before operation completes and callback. To test it, just create a class variable for agsArcGISFeature or add it to a print statement.
print("addAttachment() completed successfully for \(agsArcGISFeature)")
Hope this helps!
Regards,
Nimesh
I suspect, agsArcGISFeature is getting released before operation completes and callback. To test it, just create a class variable for agsArcGISFeature or add it to a print statement.
print("addAttachment() completed successfully for \(agsArcGISFeature)")
Hope this helps!
Regards,
Nimesh
Wow! That was it. Working like a charm now. Thanks.