2017-05-31 40 views
0

我在iOS应用程序中使用Uber-SDK。在过去的几天里,我可以通过ridesClient.fetchCheapestProduct()获得最便宜的产品。但今天,该函数总是返回一个nil值。Rides-ios-sdk - 获取最便宜的产品

这是服务器还是SDK的问题?请帮我解决这个问题。 (我在越南和我client_id仍然能正常为Android)

这是我的代码:

let ridesClient = RidesClient() 
let button = RideRequestButton() 

override func viewDidLoad() { 
    super.viewDidLoad() 

    let pickupLocation = CLLocation(latitude: 37.775159, longitude: -122.417907) 
    let dropoffLocation = CLLocation(latitude: 37.6213129, longitude: -122.3789554) 

    //make sure that the pickupLocation and dropoffLocation is set in the Deeplink 
    var builder = RideParametersBuilder() 
     .setPickupLocation(pickupLocation) 
     // nickname or address is required to properly display destination on the Uber App 
     .setDropoffLocation(dropoffLocation, nickname: "San Francisco International Airport") 

    // use the same pickupLocation to get the estimate 
    ridesClient.fetchCheapestProduct(pickupLocation: pickupLocation, completion: { product, response in 
     if let productID = product?.productID { //check if the productID exists 
      builder = builder.setProductID(productID) 
      self.button.rideParameters = builder.build() 

      // show estimate in the button 
      self.button.loadRideInformation() 
     } 
    }) 


    // center the button (optional) 
    button.center = view.center 

    //put the button in the view 
    view.addSubview(button) 
} 

回答

1

确保您设置一个server token in your Info.plist。这允许RidesClient()进行价格估算API调用。

将此片段复制到您的Info.plist(右键单击并选择Open As> Source Code),并将YOUR_SERVER_TOKEN替换为仪表板中的Server Token(确保使用与您的客户端ID相对应的服务器令牌)。

<key>UberServerToken</key> 
<string>YOUR_SERVER_TOKEN</string>