我在Uber创建了一个开发者帐户,获得了客户端ID。
在info.plist
<key>UberClientID</key>
<string>MyClientID</string>
<key>UberCallbackURI</key>
<string>MyCallBackURI</string>
不确定要放入UberCallbackURI的内容,但请遵循链接中的教程:
http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html
此外,我在appDidFinishLauncing中设置了以下设置:
Configuration.setSandboxEnabled(true)
只需按一个简单的按钮即可调用优步。
let behavior = RideRequestViewRequestingBehavior(presentingViewController: self)
behavior.modalRideRequestViewController.rideRequestViewController.delegate = self
// Optional, defaults to using the user’s current location for pickup
let location = CLLocation(latitude: 37.787654, longitude: -122.402760)
let parameters = RideParametersBuilder().setPickupLocation(location).build()
let button = RideRequestButton(rideParameters: parameters, requestingBehavior: behavior)
self.view.addSubview(button)
我还在viewController中实现了以下委托:
extension ViewController : RideRequestViewControllerDelegate {
func rideRequestViewController(rideRequestViewController: RideRequestViewController, didReceiveError error: NSError) {
let errorType = RideRequestViewErrorType(rawValue: error.code) ?? .Unknown
// Handle error here
switch errorType {
case .AccessTokenMissing:
print("Access Token Missing")
break
// No AccessToken saved
case .AccessTokenExpired:
print("Access Token Expired")
break
// AccessToken expired / invalid
case .NetworkError:
print("Network error")
break
// A network connectivity error
case .NotSupported:
print("Not Supported")
break
// The attempted operation is not supported on the current device
case .Unknown:
print("Unknown")
break
// Other error
}
}
}
当我点击按钮时,SDK会将我发送到UBER的loginscreen。当我登录时。
它始终打印来自代表的“访问令牌丢失”。
有人可以帮助我吗?
答案 0 :(得分:1)
您收到该错误是因为登录失败。我认为你的问题与你的UberCallbackURI有关。在developer dashboard的授权标签上,您需要设置重定向网址。您还需要将此值作为Info.plist
中 UberCallbackURI 的值。
我建议使用特定于您的应用的唯一网址方案(如您提供的链接中所述)