addAttachment never returns

166
2
Jump to solution
07-07-2020 04:18 PM
WorthSparks
New Contributor III

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.

0 Kudos
1 Solution

Accepted Solutions
NimeshJarecha
Esri Regular Contributor

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

View solution in original post

0 Kudos
2 Replies
NimeshJarecha
Esri Regular Contributor

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

View solution in original post

0 Kudos
WorthSparks
New Contributor III

Wow! That was it. Working like a charm now. Thanks.

0 Kudos