メインコンテンツまでスキップ

ナビゲーション情報を送信

現在の案内地点を表す NavigationInfoModel を作成し、デバイスへ送信します。

前提条件

  • デバイスが接続済みで、TurnByTurnNavigationAPI に準拠していること。
  • instructionroadName が、それぞれ 128 バイト以内であること。
  • 距離と時間には、モデルで定義された単位を使用すること。

API リファレンス

フレームワーク

AIBuds.xcframework

プロトコル

Swift
/// Turn by turn navigation API
protocol TurnByTurnNavigationAPI: DeviceAPI {
    /// Send navigation info
    /// - Parameters:
    ///   - info: Navigation info
    ///   - completion: A closure that is called when the operation completes.
    ///     - success: `true` if the operation was successful; otherwise `false`.
    ///     - statusCode: The status code returned by the device. `nil` if the operation failed.
    ///     - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
    func sendNavigationInfo(
        _ info: NavigationInfoModel,
        completion: AIBudsStatusCodeCompletionHandler?
    )
}

API リファレンスの sendNavigationInfo も参照してください。

ナビゲーションモデル

プロパティ内容
nextStepDistanceText300m1.5km など、そのまま表示できるテキスト。
maneuverナビゲーション案内で定義された raw value。
instruction案内文。最大 128 バイト。
roadName道路名。最大 128 バイト。
alertInfo任意の NavigationAlertInfoModelナビゲーション警告に定義された値とパラメータの規則を使用します。
mapProviderNavigationMapProvider で定義された raw value。
transportModeNavigationTransportMode で定義された raw value。
remainingTime残り時間(秒)。
remainingDistance残り距離(メートル)。

使用例

Swift
guard let device = device as? TurnByTurnNavigationAPI else { return }

let info = NavigationInfoModel()
info.nextStepDistanceText = "300m"
info.maneuver = NSNumber(value: NavigationManeuver.right.rawValue)
info.instruction = "Turn right"
info.roadName = "Market Street"
info.remainingTime = 420
info.remainingDistance = 1800

device.sendNavigationInfo(info) { success, statusCode, error in
    guard success else {
        print(error?.localizedDescription ?? "Navigation update failed")
        return
    }
    print("Navigation sent: \(statusCode?.stringValue ?? "Unavailable")")
}

エラー処理

送信前にバイト数の上限を検証してください。結果の判定には success を使用し、デバイスから返された statusCode も保持します。現在の公開 SDK では、各ステータスコードの意味は個別に定義されていません。