I am applying applyEdits function on featureTable, but I am not getting any response. What may be the reasons for it?

719
5
Jump to solution
09-27-2018 07:50 AM
AsimKarel
New Contributor II

Below is my code. I am not getting any response, neither success nor any failure.  URL for FeatureServer is my organisations's FeatureServer Url.

      self.pointFeatureTable = AGSServiceFeatureTable(url: URL(string: url)!)

        let point:AGSPoint = AGSPoint(clLocationCoordinate2D: CLLocationCoordinate2D(latitude: 32.7157, longitude: 117.1611))

        

        self.pointFeatureTable.credential = MyAGSHelper.sharedInstance().getCredentials();

        self.pointFeatureTable.load { (error:Error?) in

            if let error = error {

                print(error.localizedDescription)

            }

            else{

                let feature:AGSFeature = self.pointFeatureTable.createFeature(attributes: ["test":"test"], geometry: point)

                self.pointFeatureTable.add(feature) { (error: Error?) -> Void in

                    if let error = error {

                        print("Error while adding feature :: \(error.localizedDescription)")

                        return

                    }

                    else{

                        self.pointFeatureTable.applyEdits { (result, error) in

                            if let error = error {

                                print("Error while adding feature :: \(error.localizedDescription)")

                                return

                            }

                            else{

                                print(result!)

                            }

                        }

                    }

                    

                }

            }

        }

Please help and let me know it there is any mistake. !

0 Kudos
1 Solution

Accepted Solutions
Nicholas-Furness
Esri Regular Contributor

As soon as your pointFeatureTable variable goes out of scope it'll be deallocated, and so there's nothing left to call back into your callback blocks. Try creating a class-level variable to keep your pointFeatureTable reference in, or derive it from a layer in the map (the map will keep a layer reference, and the layer will keep a table reference).

See this sample, where the featureTable variable is defined at the class level, so will exist as long as the owning class does.

View solution in original post

5 Replies
Nicholas-Furness
Esri Regular Contributor

As soon as your pointFeatureTable variable goes out of scope it'll be deallocated, and so there's nothing left to call back into your callback blocks. Try creating a class-level variable to keep your pointFeatureTable reference in, or derive it from a layer in the map (the map will keep a layer reference, and the layer will keep a table reference).

See this sample, where the featureTable variable is defined at the class level, so will exist as long as the owning class does.

AsimKarel
New Contributor II

As you can see in my code it is self.pointFeatureTable, so it is already a class variable.
In my class I have declared it as: 
private var pointFeatureTable:AGSServiceFeatureTable!

0 Kudos
Nicholas-Furness
Esri Regular Contributor

Oh yes, I'm sorry. I missed the "self".

You could do a couple of things to dig in.

  1. I assume the service URL is HTTPS and not HTTP. If it's HTTP, make sure your App Transport Security settings allow that.
  2. Turn on debugging on the global AGSRequestConfiguration to see what's being sent and what, if anything, is being returned.
    AGSRequestConfiguration.global().debugLogRequests = true
    AGSRequestConfiguration.global().debugLogResponses = true‍‍

Let me know what you find.

AsimKarel
New Contributor II

Hey @Nicholas! Thanks for the help. Actually your first solution worked with some modifications, I declared and initialized the pointFeatureTable at the class level itself, and it resolved my issue. Earlier I only declared the variable at class level, not initialized at class level.

Working code:
class MyClass{

   lazy var pointFeatureTable:AGSServiceFeatureTable = AGSServiceFeatureTable(url: URL(string: myURL)!)

   func myFunc(){

      //rest of the above mentioned code

   }

}

0 Kudos
Nicholas-Furness
Esri Regular Contributor

Glad it working for you, but that's odd. It shouldn't matter. I just tried to reproduce this with your original code and it adds features fine.

Could you have made some other edit to the code in the meantime? Can you try setting self.pointFeatureLayer as in your original code again just as a sanity check?