AnsweredAssumed Answered

How do I get feature data from a feature layer using the ArcGIS iOS SDK?

Question asked by txpost on Dec 31, 2017
Latest reply on Jan 31, 2018 by txpost

Hi everyone,

 

I'm building an AR app using ARKit and the ArcGIS iOS SDK. I'm trying to access the data of a Feature Layer which I'm hosting on ArcGIS Online. The Feature Layer consists of images which have been submitted by participants through a Crowdsource Story Map. Specially, I'm trying to get the location and URL of each image in the Feature Layer, using the ArcGIS iOS SDK, so that I can then place/display them in the AR app based on that information.

 

I've been working on this problem for a few days now and have been unable to come up with a solution. I'll share what I have so far, below. Any help would be greatly appreciated!

 

// Connect to the ArcGIS Online portal
let portal = AGSPortal(url: URL(string: "https://organizationName.maps.arcgis.com")!, loginRequired: false)

 

// Provide credentials
portal.credential = AGSCredential(user: "username", password: "password")

 

// Get the portal item
let portalItem = AGSPortalItem(portal: portal, itemID: "xxxx836axxxx4781xxxxe4d58bcxxxx")

 

// Next I load the portal item
portalItem.load { [weak self] (error) -> Void in

    if let error = error {
        print("Could not load portal item due to error : \(error)")
        return
    }

 

    // Printing the portal item to the console produces the result I'm looking for. I'm getting the correct portal item.
    print("portal item is loaded \(portalItem)")

 

   // The above print statements outputs the following:
   // portal item is loaded xxxx836axxxx4781xxxxe4d58bcxxxx, Feature Service, featureLayerName, organizationName, https://organizationName.maps.arcgis.com/sharing/rest/content/items/xxxx836axxxx4781xxxxe4d58bcxxxx/data
}

 

// Then I try to fetch the data of the portal item. This is where I get stuck. I would have thought this grabs the data of the feature layer, which would then let me get the data for each specific feature but it doesn't fetch any data (print statement outputs "0 bytes")

portalItem.fetchData { [weak self](data, error) -> Void in


    if let error = error {
        print("Could not fetch data due to error: \(error.localizedDescription)")
        return
    }

    // Print statement is reached but output is "0 bytes"
    if let data = data {
        print(data)
    }
}

 

I apologize if there is a better way to post code on this forum. Again, any help would be awesome!

 

Trevor

Outcomes