Navigation जानकारी भेजें
मौजूदा route step के लिए NavigationInfoModel बनाएँ और device को भेजें।
आवश्यक शर्तें
- Device connected हो और
TurnByTurnNavigationAPIconform करता हो। instructionऔरroadNameमें से हर value अधिकतम 128 bytes हो।- Distance और time में model द्वारा documented units उपयोग हों।
API Reference
Framework
AIBuds.xcframework
Protocol की घोषणा
- 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 Reference में sendNavigationInfo देखें।
Navigation model
| Property | अर्थ |
|---|---|
nextStepDistanceText | 300m या 1.5km जैसा display-ready text। |
maneuver | Navigation निर्देश में defined raw value। |
instruction | अधिकतम 128 bytes का instruction text। |
roadName | अधिकतम 128 bytes का road name। |
alertInfo | Optional NavigationAlertInfoModel; Navigation alerts के values और parameter rules उपयोग करें। |
mapProvider | NavigationMapProvider द्वारा defined raw value। |
transportMode | NavigationTransportMode द्वारा defined raw value। |
remainingTime | बचा समय, seconds में। |
remainingDistance | बची दूरी, meters में। |
उपयोग के उदाहरण
- 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);
}];Error handling
भेजने से पहले byte limits validate करें। success को primary result मानें और device statusCode सुरक्षित रखें; public SDK अभी individual status codes का अर्थ document नहीं करता।