길 안내 정보 전송
현재 경로 단계에 맞는 NavigationInfoModel을 생성하여 기기로 전송합니다.
사전 요구 사항
- 기기가 연결되어 있고
TurnByTurnNavigationAPI를 준수합니다. instruction과roadName은 각각 128 byte 이하여야 합니다.- 거리와 시간에는 모델에 정의된 단위를 사용합니다.
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 byte의 안내 문구입니다. |
roadName | 최대 128 byte의 도로명입니다. |
alertInfo | 선택적 NavigationAlertInfoModel입니다. 길 안내 경고의 값과 매개변수 규칙을 따르세요. |
mapProvider | NavigationMapProvider에 정의된 raw value입니다. |
transportMode | NavigationTransportMode에 정의된 raw value입니다. |
remainingTime | 남은 시간(초)입니다. |
remainingDistance | 남은 거리(m)입니다. |
사용 예제
- 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);
}];오류 처리
전송하기 전에 byte 제한을 확인하세요. success를 기본 결과로 사용하고 기기의 statusCode를 보관하세요. 현재 공개 SDK에는 개별 상태 코드의 의미가 정의되어 있지 않습니다.