Navigasyon Bilgilerini Gönderme
Güncel rota adımı için bir NavigationInfoModel oluşturup cihaza gönderin.
Ön Koşullar
- Cihaz bağlıdır ve
TurnByTurnNavigationAPIprotokolüne uyar. instructionveroadNamedeğerlerinin her biri en fazla 128 bayttır.- Mesafe ve süre için modelde belirtilen birimler kullanılır.
API Referansı
Framework
AIBuds.xcframework
Protokol
- 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 Referansındaki sendNavigationInfo öğesine bakın.
Navigasyon Modeli
| Özellik | Anlamı |
|---|---|
nextStepDistanceText | 300m veya 1.5km gibi gösterime hazır metin. |
maneuver | Navigasyon Manevraları tarafından tanımlanan raw değer. |
instruction | En fazla 128 baytlık yönlendirme metni. |
roadName | En fazla 128 baytlık yol adı. |
alertInfo | İsteğe bağlı NavigationAlertInfoModel; Navigasyon Uyarıları bölümündeki değerleri ve parametre kurallarını kullanın. |
mapProvider | NavigationMapProvider tarafından tanımlanan raw değer. |
transportMode | NavigationTransportMode tarafından tanımlanan raw değer. |
remainingTime | Saniye cinsinden kalan süre. |
remainingDistance | Metre cinsinden kalan mesafe. |
Kullanım Örnekleri
- 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);
}];Hata Yönetimi
Göndermeden önce bayt sınırlarını doğrulayın. Temel sonuç olarak success değerini kullanın ve cihazın statusCode değerini koruyun; genel SDK şu anda ayrı durum kodlarının anlamını belgelemez.