Airbox 0.0.11

Airbox 0.0.11

Heenabpargoe维护。



 
依赖
Alamofire~> 4.9.0
MBProgressHUD~> 1.0.0
 

Airbox 0.0.11

  • bpargoe

Airbox iOS SDK

为iPhone应用程序安装Airbox以确保安全的交付。Airbox SDK通过CocoaPods分发。下文详细说明此方法

预置条件

  1. Airbox SDK支持iOS 9.0及以上。

  2. Airbox App_Secret_Key

  3. Xcode

如果您在集成过程中有任何疑问,请通过[email protected][email protected][email protected]联系我们。

第一步:使用CocoaPods安装

Airbox SDK可以通过CocoaPods获取。要将Airbox SDK添加到项目中,请将SDK添加到以下Podfile中。

pod 'Airbox'

一旦您的Podfile已更新,请运行pod install(终端命令)以自动下载并安装SDK到您项目中。

请注意:Airbox SDK支持针对iOS 9.0+的应用程序。SDK本身与iOS 9.0及以上所有版本兼容。

升级Airbox SDK吗?

在您的项目目录中运行pod update命令(Airbox,终端命令)。

第二步:为顾客和司机初始化Airbox SDK

在调用/尝试任何Airbox SDK的功能/方法之前,请按照以下步骤执行初始化操作

Airbox凭证是通过APP-SECRET-KEY添加的。

添加凭证并初始化Airbox SDK

AirboxAppType
   customer //AirboxAppType for customer app 
   driver  // AirboxAppType for driver app 

注意:不要忘记将以下代码段中的YOUR-APP-SECRET-KEY替换为实际的app密钥。

 AirboxManager.shared.initializeAirbox(withAppSecretKey: `YOUR-APP-SECRET-KEY`, appType: AirboxAppType, callBack: { (response, error) in
    if error != nil {
    return
 }
})

顾客可访问的功能

1. 选择私有/公共Airbox:

从AirboxManager的openSelectAirboxController函数调用。它需要三个参数,即UIViewController(可选)、纬度和经度。在选择空气箱后,您将获得一个回调,其中包含响应和错误。如果响应不为空,则您将获得以下键,否则您将获得一些错误。

"airboxLatitude" - 是空气箱位置的纬度。

"airboxLongitude" - 是空气箱位置的经度。

"airboxName" - 空气箱的名称。

"sessionId" - 是唯一的ID,请在您的端保存。创建预订时需要它。

AirboxManager.shared.openSelectAirboxController(on: UIViewController, latitute: `YOUR_BOOKING_LATITUDE`, longitute: `YOUR_BOOKING_LONGITUDE`, callBack: { (response, error) in
    guard error == nil else {
    if error?.errorType == AirboxErrorType.sessionExpired {
    // Reinitialize Airbox SDK
     }
    return
  }
    guard response as?[String: Any] else {return}
    let sessionId = response[“sessionId”] as? String ?? “”
    let airboxLat = response[“airboxLatitude”] as? String ?? “”
    let airboxLong = response[“airboxLongitude”] as? String ?? “”
    let airboxName = response[“airboxName”] as? String ?? “”
    //Save response 
})

2. 创建预订:-

从AirboxManager调用createBooking函数。它需要一个参数,即sessionId,该参数是在选择私有/公共空气箱流程期间创建的。在成功的响应中,它将返回airboxBookingId,请将其保存以进行后续步骤。

AirboxManager.shared.createBooking(sessionId: self.airboxSessionId, callBack: { (response,error) in
   guard error == nil else {
   if error?.errorType == AirboxErrorType.sessionExpired {
   // Reinitialize Airbox SDK
   }
   return
   }
   guard response as? [String: Any] else {return}
   let airboxBookingId = response[“airboxBookingId”] as? String ?? “”
   //Save response
})

3. 确认预订:-

您必须通过调用以下函数告诉我们您的预订已成功创建/取消。从AirboxManager调用confirmBooking函数。

BOOKING_STATUS:-
confirm booking = 1
cancel booking  = 2
 AirboxManager.shared.confirmBooking(airboxBookingId: airboxBookingId, bookingStatus: 'BOOKING_STATUS', externalBookingId: 'YOUR_BOOKIBG_ID', callBack: { (response,error) in
    guard error == nil else {
    if error?.errorType == AirboxErrorType.sessionExpired {
    // Reinitialize Airbox SDK
    }
    return
    }
        //Save Response
})

4. 开关空气箱(客户):-

从AirboxManager调用openCloseAirboxForCustomer函数。以下是需要参数:

  1. airboxBookingId: 在创建预订期间生成。
  2. state: 1为打开空气箱,2为关闭空气箱。
  3. bookingCustomerToken: 在司机成功交付订单时生成。

在成功的响应中,它将返回空气箱的状态。

AIRBOX_STATE:-
OPENED = 1
CLOSED = 2
ERROR = 3
PROCESSING = 4

注意:如果空气箱响应延迟,则此api的响应时间将比通常的api长。有关空气箱开启/关闭通知,请参阅第3步。

AirboxManager.shared.openCloseAirboxForCustomer(airboxBookingId: airboxBookingId, state: 'STATE', bookingCustomerToken: 'BOOKING_CUSTOMER_TOKEN', callBack: {  (response,error) in
    guard error == nil else {
    if error?.errorType == AirboxErrorType.sessionExpired {
    // Reinitialize Airbox SDK
    }
    return
    }
    guard response as? [String: Any] else {return}
    let airboxState = response[“state”] as? String ?? “”
    //Save response
})

5. 确认包裹派送(客户):

您必须确认包裹是否成功派送或备注。通过调用以下函数。从AirboxManager中调用customerPackageDelivered函数。

注意:请在驾驶员成功派送包裹后使用此函数。如果在此函数之前至少打开或关闭了一次Airbox,则会抛出错误。因此,打开/关闭Airbox是调用此函数的前提条件。

 AirboxManager.shared.customerPackageDelivered(airboxBookingId: airboxBookingId, callBack: { (response,error) in
    guard error == nil else {
    if error?.errorType == AirboxErrorType.sessionExpired {
    // Reinitialize Airbox SDK
    }
    return
    }
    guard response as? [String: Any] else {return}
    //Save response
})

驾驶员可访问功能

1. 打开/关闭Airbox(驾驶员):

从AirboxManager调用openCloseAirboxForDriver函数。以下是需要参数:-

  1. airboxBookingId: 在创建预订期间生成。
  2. state: 1为打开空气箱,2为关闭空气箱。
  3. driverId:在驾驶员注册时生成。

在成功的响应中,它将返回空气箱的状态。

AIRBOX_STATE:
OPENED = 1
CLOSED = 2
ERROR = 3
PROCESSING = 4

注意:如果空气箱响应延迟,则此api的响应时间将比通常的api长。有关空气箱开启/关闭通知,请参阅第3步。

  AirboxManager.shared.openCloseAirboxForDriver(airboxBookingId: airboxBookingId, state: `STATE', driverId: 'DRIVER_ID', callBack: { (response,error) in
        guard error == nil else {
    if error?.errorType == AirboxErrorType.sessionExpired {
    // Reinitialize Airbox SDK
    }
    return
    }
    guard response as? [String: Any] else {return}
    let airboxState = response[“state”] as? String ?? “”
    //Save response
})

2. 包裹派送请求:

从AirboxManager调用packageDeliveryRequest函数启动派送请求。在成功的响应中,它将返回bookingCustomerToken,请将其保存在您的端,因为将需要在客户端调用函数时使用。

    AirboxManager.shared.packageDeliveryRequest(airboxBookingId:airboxBookingId, driverId: 'DRIVER_ID', callBack: { (response,error) in
    guard error == nil else {
    if error?.errorType == AirboxErrorType.sessionExpired {
    // Reinitialize Airbox SDK
    }
    return
    }
    guard response as? [String: Any] else {return}
    let bookingCustomerToken = response[“bookingCustomerToken”] as? String ?? “”
})

3. 确认派送请求:

您必须确认包裹已成功送达客户的航空箱子。从AirboxManager调用确认包裹送达功能 confirmPackageDelivered。

递送状态
CONFIRMED = 1
CANCEL    = 2
AirboxManager.shared.confirmPackageDelivered(airboxBookingId: airboxBookingId, driverId: 'DRIVER_ID', status: 'DELIVERY_STATUS', callBack: { (response,error) in
    guard error == nil else {
    if error?.errorType == AirboxErrorType.sessionExpired {
    // Reinitialize Airbox SDK
    }
    return
    }
  })

获取Airbox实时状态的功能

此功能用于获取Airbox的实时状态。只需要airboxBookingId即可。此功能客户和司机均可访问。

在成功响应时,它返回Airbox的状态。

AIRBOX_STATE::
OPENED = 1
CLOSED = 2
ERROR = 3
PROCESSING = 4
AirboxManager.shared.getLiveStateOfAirbox(airboxBookingId: airboxBookingId) {  (response, error) in
    guard error == nil else {
    if error?.errorType == AirboxErrorType.sessionExpired {
    // Reinitialize Airbox SDK
    }
    return
    }
    guard response as? [String: Any] else {return}
    let airboxState = response[“state”] as? String ?? “”
    //Save response
 })

在航空箱子中取消预订

From the AirboxManager call function cancelBooking to cancel Booking at Airbox. This requires airboxBookingId only
 AirboxManager.shared.cancelBooking(airboxBookingId: airboxBookingId, callBack: { (response,error) in
          guard error == nil else {
   if error?.errorType == AirboxErrorType.sessionExpired {
   // Reinitialize Airbox SDK
   }
   return
   }
   guard response as? [String: Any] else {return}
   //Save response
})

步骤3:处理客户和司机的推送通知

1:发送设备注册令牌:

Airbox SDK 能够发送推送通知给用户。要启用此支持,当您的应用程序代理接收到应用:didRegisterForRemoteNotificationsWithDeviceToken: 方法时,请添加 registerDeviceToken(deviceToken: Data) 的调用,如下所示

func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
 AirboxManager.shared.registerDeviceToken(deviceToken: deviceToken)
}

2: 处理推送通知

接收到远程通知后,将remoteNotification userInfo传递到handlePushNotification(withUserInfo: userInfo)方法中,以验证Airbox SDK通知,如下所述

func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
if AirboxManager.shared.isAirboxNotification(userInfo: userInfo) {
    AirboxManager.shared.handlePushNotification(withUserInfo: userInfo)
    return
 }
}

注意:如果在上面的任何函数中抛出错误,它将是AirboxError类型,它将包含以下值

  1. errorType: 它有两种类型。a) sessionExpired - 在这种情况下,您需要再次重新初始化Airbox Sdk。b) default - 在所有其他情况下,您都将收到此错误类型。
  2. message: 错误消息。
  3. statusCode: 错误的状态码。