问题
I'm having some trouble finding a way to do this. I got an app that uses Uber SDK for iOS. I was able to add the "RideRequestButton" with "Ride there with Uber" text to do a deeplink to the Uber app. Also, I'm done requesting the token using SSO and fetch the token with Request scope. Now the problem is... I'm not sure how to fetch the status of the current ride request made via the deeplink. Is this possible?
Thanks!
I tried following an algorithm mentioned in one of the thread which is to use the RidesClient to fetch the current ride then get the current ride detail after obtaining the ride requestID. Here's a glimpse of my code:
func refreshRideRequestStatus () {
var requestID: String = ""
self.ridesClient.fetchCurrentRide({
ride, response in
if (ride != nil) {
print ("[refreshRideRequestStatus] ride:", ride ?? "no active ride")
requestID = (ride?.requestID)!
}
else {
print ("[refreshRideRequestStatus] ride: no active ride")
print ("[refreshRideRequestStatus] response: ", response.response ?? "no response")
}
})
if (requestID.isEmpty) {
print ("[refreshRideRequestStatus] no active request")
}
else {
print ("[refreshRideRequestStatus] requestID: ", requestID)
self.ridesClient.fetchRideDetails(requestID, completion: {
ride, response in
self.isTorchUberFlashable = false
if (response.statusCode == 200) {
let status:Int = (ride?.status)!.rawValue
print("refreshRideRequestStatus] status:", status)
switch (status) {
case 1:
print("[refreshRideRequestStatus] accepted")
case 2:
print("[refreshRideRequestStatus] arriving")
case 3:
print("[refreshRideRequestStatus] completed")
case 4:
print("[refreshRideRequestStatus] driverCanceled")
case 5:
print("[refreshRideRequestStatus] inProgress")
case 6:
print("[refreshRideRequestStatus] noDriversAvailable")
case 7:
print("[refreshRideRequestStatus] processing")
case 8:
print("[refreshRideRequestStatus] ridersCanceled")
case 9:
print("[refreshRideRequestStatus] unknown")
default:break
}
}
else {
print("[refreshRideRequestStatus] error: ", response.response ?? "no data request found")
}
})
}
}
The function above is going to be called every time my app is set to foreground or became active.
Sorry but another question would be. How will I know if this will work and is there a way to test this by requesting a real ride and complete a whole transaction?
回答1:
With the request
scope, you are only able to look at the status of rides that are initiated using your auth token. So if the user is deeplinking into the app and then requesting a ride from there, you will not have access to that information.
In order to get this information, you would be required to get authorized for the all_trips
scope.
来源:https://stackoverflow.com/questions/42387082/uber-sdk-for-ios-get-real-time-ride-request-status-made-via-deep-link