When view controller is loaded, it makes an API call to our server with the app identifier which is used by the API to generate a token using ArcGIS service. The response contains portal URL, token and mapId. The portal URL can be of following format:
and then use following code to load map and related basemaps
agsCredential = AGSCredential(token: portalToken, referer: referer)
let portal = AGSPortal(url: portalURL, loginRequired: true)
portal.credential = agsCredential
let portalItem = AGSPortalItem(portal: portal, itemID: mapId)
let map = AGSMap(item: portalItem)
esriMapView.map = map
map.load { (error) in
// handle error or handle successfully loaded map
// load base maps
}
Although I have provided the credentials, I still see credential challenge popup. If I create AGSCredentials using userName and password, it works fine.
Our requirement is to use token rather than userName and password, what is the best approach to use the token?
I also been communication on git, so I tried and what worked is in following link of ESRI iOS Repo.
https://github.com/Esri/arcgis-runtime-samples-ios/issues/1012
What type of layers present in the portalItem? Are they hosted feature layers? If yes, it requires another credential/token generated using portalToken. Can you please post the credential challenge information?
Regards,
Nimesh
Hi Nimesh,
The layers I wan to access are within the basemap, how set credentials again? Following is how I am doing right now. Also what credential challenge information are you after?
let agsCredentials = AGSCredential(token: credentialToken, referer: referer)
let portal = AGSPortal(url: portalURL, loginRequired: true)
portal.credential = agsCredentials
let portalItem = AGSPortalItem(portal: portal, itemID: mapId)
let map = AGSMap(item: portalItem)
esriMapView.map = map
map.load { (error) in
if let _ = error {
print(error!.localizedDescription)
self.delegate?.mapLoadingFailed()
} else {
var layers = MapSpecificLayers()
for layer in map.operationalLayers {
if let agsLayer = layer as? AGSLayer {
let mSpecifiLayer = MapSpecificLayer(id: agsLayer.layerID,
layerName: agsLayer.name,
isVisible: agsLayer.opacity == 0 ? false : true)
layers.append(mSpecifiLayer)
}
}
self.layersViewModel.mapSpecificLayersFetched(mapSpecificLayers: layers)
self.delegate?.mapLoaded()
}
}
portal.fetchBasemaps { (bmaps, err) in
print(">>>>>. BASE MAP FETCHED \(bmaps?.count)<<<<<")
}
Can you capture all request/responses and send to me in direct message? If possible, send a reproducible sample project too so I can help you where to set another credential.
Regards,
Nimesh