Select to view content in your preferred language

Error getting default parameters: Cannot call this method in this context

1571
13
02-24-2019 10:53 AM
SamerAbraham
New Contributor

Hello

I'm calling the route service from iOS as follows:

let routeTask = AGSRouteTask(url: URL(string: "https://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World")!)

routeTask.defaultRouteParameters { [weak self] (defaultParameters, error) in guard error == nil else {

print("Error getting default parameters: \(error!.localizedDescription)")

return

}

I keep hitting the error condition with Error Code 15 stating "Error getting default parameters: Cannot call this method in this context".

Anyone have any leads on what might cause this?

Thanks

0 Kudos
13 Replies
Nicholas-Furness
Esri Regular Contributor

That's the right URL. Should just work (I can't reproduce it here).

Is your routeTask going out of scope for some reason?

And which version of the Runtime SDK are you using?

0 Kudos
SamerAbraham
New Contributor

It's 100.4.  I can't get it to work.

0 Kudos
PhilipGruenler
Esri Contributor

Are you providing a credential to the routeTask or logging in when prompted?  The world routing service is a paid service and requires a login.

0 Kudos
SamerAbraham
New Contributor

Yes I was using my keys.

0 Kudos
SamerAbraham
New Contributor

I should also say that that would be a terrible error message for missing creds or payment info.  Since it's iOS this is how the example shows you to handle sign in at the AppDelegate:

private func setupOAuthManager() {

        let config = AGSOAuthConfiguration(portalURL: nil, clientID: AppConfiguration.clientID, redirectURL: "\(AppConfiguration.urlScheme)://\(AppConfiguration.urlAuthPath)")

        AGSAuthenticationManager.shared().oAuthConfigurations.add(config)

        AGSAuthenticationManager.shared().credentialCache.enableAutoSyncToKeychain(withIdentifier: AppConfiguration.keychainIdentifier, accessGroup: nil, acrossDevices: false)

    }

Once you do that you get a sign in page so I signed in using my id.  

0 Kudos
Nicholas-Furness
Esri Regular Contributor

Comment out the line AGSAuthenticationManager.shared().oAuthConfigurations.add(config).

Then when you call routeTask.defaultRouteParameters you should be prompted with an alert box for your credentials instead. If you enter your credentials (it should be a free developer account or an ArcGIS Online organizational account, not a personal account), you'll be fine.

I think there may be one of two things going on:

1. You're using a personal Esri account OR

2. There's an issue with how your app's OAuth configuration is being defined. But if you're entering your credentials through the OAuth page and control returns to your app, that doesn't seem likely to be the case.

If it turns out to be 1) above, yes, I agree, that error message is not good and we'll have to improve that.

Let me know if this helps.

0 Kudos
Nicholas-Furness
Esri Regular Contributor

Hi Samer Abraham. Were you able to make any progress? Was it the type of account that you were using?

0 Kudos
SamerAbraham
New Contributor

Sorry to be honest I totally gave up on this as I was able to solve it quickly with a different vendor. 

I spent a little time on it just now since you asked and it's easy to switch implementation.  I removed the auth line from AppDelegate, I got prompted when the call was made, and the ordered list is returned.  Since I'm using the same creds I was using before I would guess it was 2) from your two possibilities above.

0 Kudos
Nicholas-Furness
Esri Regular Contributor

It sounds like it.

Assuming you used the Maps App as your starting point, did you follow the steps in "Register an Application" and "Configure the project"? I'm intrigued as to precisely what went wrong so that I can see if we can do better with the instructions and the error messages.

0 Kudos