将Uber与我的应用集成

时间:2016-08-07 14:52:00

标签: ios uber-api

当我点击按钮时,我试图制作超级按钮我想要的是打开uber app with dropoff Location。

我已经在那里读过api(https://github.com/uber/rides-ios-sdk)并且我完全按照它说的做了但是当我按下uber按钮时它所做的就是打开超级应用程序而没有任何下降位置。

我的代码请指导我

CLLocation *loc = [[CLLocation alloc]initWithLatitude:26.410640 longitude:50.099568];

UBSDKRideRequestButton *button = [[UBSDKRideRequestButton alloc] init];
UBSDKRidesClient *ridesClient = [[UBSDKRidesClient alloc] init];
CLLocation *pickupLocation = [[CLLocation alloc] initWithLatitude: self.locationManager.location.coordinate.latitude longitude: self.locationManager.location.coordinate.longitude];
CLLocation *dropoffLocation = [[CLLocation alloc] initWithLatitude: loc.coordinate.latitude longitude: loc.coordinate.longitude];
__block UBSDKRideParametersBuilder *builder = [[UBSDKRideParametersBuilder alloc] init];
builder = [builder setPickupLocation: pickupLocation];
builder = [builder setDropoffLocation: dropoffLocation];
[ridesClient fetchCheapestProductWithPickupLocation: dropoffLocation completion:^(UBSDKUberProduct* _Nullable product, UBSDKResponse* _Nullable response) {
    if (product) {
        builder = [builder setProductID: product.productID];
        button.rideParameters = [builder build];
        [button loadRideInformation];
    }
}];

[self.view addSubview:button];

1 个答案:

答案 0 :(得分:1)

从技术上讲,RideRequestButton使用深层链接将参数发送到优步应用。如DelegatesToMessageHandlerInterface所述,您必须为该位置提供昵称或格式化地址。否则,引脚将不会显示。

我更新了您的代码以实现这一目标。你会尝试一下,让我知道这是否有效?

CLLocation *dropoffLocation = [[CLLocation alloc]initWithLatitude:26.410640 longitude:50.099568];

UBSDKRideRequestButton *button = [[UBSDKRideRequestButton alloc] init];
UBSDKRidesClient *ridesClient = [[UBSDKRidesClient alloc] init];
CLLocation *pickupLocation = [[CLLocation alloc] initWithLatitude: self.locationManager.location.coordinate.latitude longitude: self.locationManager.location.coordinate.longitude];
__block UBSDKRideParametersBuilder *builder = [[UBSDKRideParametersBuilder alloc] init];
builder = [builder setPickupLocation: pickupLocation];
[[builder setPickupLocation:pickupLocation] 
builder = [builder setDropoffLocation: dropoffLocation nickname: @"Somewhere" address:@"123 Fake St."];
[ridesClient fetchCheapestProductWithPickupLocation: pickupLocation completion:^(UBSDKUberProduct* _Nullable product, UBSDKResponse* _Nullable response) {
    if (product) {
        builder = [builder setProductID: product.productID];
        button.rideParameters = [builder build];
        [button loadRideInformation];
    }
}];

[self.view addSubview:button];
相关问题