gpt4 book ai didi

android - 安卓和IOS如何跨平台

转载 作者:行者123 更新时间:2023-11-28 23:34:14 25 4
gpt4 key购买 nike

我在 Android 和 IOS 上都创建了一个应用程序。我正处于应用程序的最后一个障碍。我能够让 Android 用户与 IOS 用户一起工作,而 IOS 有一个表格 View 。

现在我面临着一个不同的问题。如果 iOS 应用程序上的“乘客”正在请求乘车并且 Android 驱动程序可用 - 我该如何完成这个用例?

如果iOS用户发出请求,流程是这样的:

func requestPressed(_ sender: Any) {
print("... requestPressed")

let dict = selectedPin!.addressDictionary
if dict?.count == 0 {
// this isn't shown to the user, just in your debug window
print("no addresses available, try again in a few seconds")
return
}

destAddress = selectedPin!.addressDictionary!["Street"] as? String ?? "None"
if destAddress == "None" {
print("no valid address available, try again in a few seconds")
return
}

if userLocation != nil {
print("my userLocation: \(userLocation!)")
if canRequestRyde { // if true ...

// get the destination area name, and the price
areaNameDestination = DriveHandler.Instance.getAreaName(latitude: destLat, longitude: destLong)
print("destination area \(areaNameDestination)")

requestFarePrice()

rRideHandler.Instance.requestRide(latitude: Double(userLocation!.latitude), longitude: Double(userLocation!.longitude), destLat: Double(destLat), destLong: Double(destLong), currentAddress: self.currentAddress, destAddress: destAddress, farePrice: farePrice)

// reset the driver message
driverMessage = ""

canRequestRide(delegateCalled: true, request: nil)

} else {

riderCancelled()
}

}

}

Firebase 条目如下所示:

RideRequests/IOS

我需要做的是让在线 Android Driver 接受/拒绝请求并按照 Android Rider vs Android Driver 的步骤进行操作。

如果 Android 请求乘车并按“请求”按钮,则执行以下步骤:

private void requestPickupHere(String uid) {

Log.e(TAG, "requestPickupHere");

DatabaseReference dbRequest = FirebaseDatabase.getInstance().getReference(Common
.request_tbl); // "RideRequests"

GeoFire mGeoFire = new GeoFire(dbRequest);
mGeoFire.setLocation(uid, new GeoLocation(Common.mLastLocation.getLatitude(),
Common.mLastLocation.getLongitude()));

// write to db
if (search_bar_destination != null) {
dbRequest.child(uid).child("destination").setValue(search_bar_destination);


} else if (tap_on_map_destination != null) {
dbRequest.child(uid).child("destination").setValue(tap_on_map_destination);
}

dbRequest.child(riderId).child("status").setValue("");

if (mUserMarker.isVisible()) {
mUserMarker.remove();
}

// Add a new marker
mUserMarker = mMap.addMarker(new MarkerOptions()
.title("Pickup Here")
.snippet("")
.position(new LatLng(Common.mLastLocation.getLatitude(), Common.mLastLocation.getLongitude()))
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));

mUserMarker.showInfoWindow();

btnRequest.setText("Getting your DRIVER ...");

location = getCompleteAddressString(Common.mLastLocation.getLatitude(), Common.mLastLocation.getLongitude());
Log.e(TAG, "riders location = " + location);

findDriver();
}

当上面的代码运行时,它会打开位于司机应用程序中的“客户调用” Activity ,司机可以在其中接受/拒绝请求。

如何将请求从 IOS Rider 发送到 Android 驱动程序,就像 Android 到 Android 一样?

最佳答案

使用不同的平台应该不是问题,当用户请求乘车时,您可以在数据库中的司机下添加一个属性,例如:

DriverRides
DriverId
Name: peter
purpose: needs a ride

然后,您可以检索要在 recyclerview 中显示该驱动程序的所有请求。用户使用什么手机并不重要,除非您希望 android 用户接受请求而 ios 用户发送请求。


您在两个平台上使用相同的数据库,因此当 ios 用户或 android 用户存储数据时,数据将转到相同的位置。例如,如果用户 x 使用 iPhone,用户 y 使用三星,您将在数据库中执行以下操作:

Users
UserId1
name: userx
age: 100
UserId2
name: usery
age: 120

关于android - 安卓和IOS如何跨平台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55598067/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com