ナビゲーション情報を送信
現在の案内地点を表す NavigationInfoModel を作成し、デバイスへ送信します。
前提条件
- デバイスが接続済みで、
TurnByTurnNavigationAPIに準拠していること。 instructionとroadNameが、それぞれ 128 バイト以内であること。- 距離と時間には、モデルで定義された単位を使用すること。
API リファレンス
フレームワーク
AIBuds.xcframework
プロトコル
- Swift
- Objective-C
/// 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?
)
}/// Turn by turn navigation API
@protocol AIBudsTurnByTurnNavigationAPI <AIBudsDeviceAPI>
/// Send navigation info
/// - Parameters:
/// - info: Navigation info
/// - completion: Reports success, device status code, and an optional error.
- (void)sendNavigationInfo:(AIBudsNavigationInfoModel *_Nonnull)info
completion:(AIBudsStatusCodeCompletionHandler _Nullable)completion;
@endAPI リファレンスの sendNavigationInfo も参照してください。
ナビゲーションモデル
| プロパティ | 内容 |
|---|---|
nextStepDistanceText | 300m や 1.5km など、そのまま表示できるテキスト。 |
maneuver | ナビゲーション案内で定義された raw value。 |
instruction | 案内文。最大 128 バイト。 |
roadName | 道路名。最大 128 バイト。 |
alertInfo | 任意の NavigationAlertInfoModel。ナビゲーション警告に定義された値とパラメータの規則を使用します。 |
mapProvider | NavigationMapProvider で定義された raw value。 |
transportMode | NavigationTransportMode で定義された raw value。 |
remainingTime | 残り時間(秒)。 |
remainingDistance | 残り距離(メートル)。 |
使用例
- Swift
- Objective-C
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")")
}id<AIBudsTurnByTurnNavigationAPI> device = (id<AIBudsTurnByTurnNavigationAPI>)self.device;
if (![device conformsToProtocol:@protocol(AIBudsTurnByTurnNavigationAPI)])
return;
AIBudsNavigationInfoModel *info = [[AIBudsNavigationInfoModel alloc] init];
info.nextStepDistanceText = @"300m";
info.maneuver = @(AIBudsNavigationManeuverRight);
info.instruction = @"Turn right";
info.roadName = @"Market Street";
info.remainingTime = @420;
info.remainingDistance = @1800;
[device
sendNavigationInfo:info
completion:^(BOOL success, NSNumber *_Nullable statusCode, NSError *_Nullable error) {
if (!success)
NSLog(@"Navigation update failed: %@", error.localizedDescription);
}];エラー処理
送信前にバイト数の上限を検証してください。結果の判定には success を使用し、デバイスから返された statusCode も保持します。現在の公開 SDK では、各ステータスコードの意味は個別に定義されていません。