适用于 iOS 的 Uber SDK - 通过深层链接获取实时乘车请求状态 [英] Uber SDK for iOS - get real time ride request status made via deep link

查看:28
本文介绍了适用于 iOS 的 Uber SDK - 通过深层链接获取实时乘车请求状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找方法时遇到了一些麻烦.我有一个使用 Uber SDK for iOS 的应用程序.我能够添加RideRequestButton"和Ride there with Uber"文本,以创建到 Uber 应用程序的深层链接.此外,我已完成使用 SSO 请求令牌并使用请求范围获取令牌.现在的问题是......我不确定如何获取通过深层链接发出的当前乘车请求的状态.这可能吗?

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?

谢谢!

我尝试遵循其中一个线程中提到的算法,即使用 RidesClient 获取当前乘车,然后在获取乘车请求 ID 后获取当前乘车详细信息.这是我的代码的一瞥:

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?

推荐答案

使用 request 范围,您只能查看使用您的身份验证令牌发起的行程的状态.因此,如果用户深层链接到应用程序,然后从那里请求乘车,您将无法访问该信息.

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.

为了获得此信息,您需要获得 all_trips 范围的授权.

In order to get this information, you would be required to get authorized for the all_trips scope.

这篇关于适用于 iOS 的 Uber SDK - 通过深层链接获取实时乘车请求状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆