头文件:
#import "iflyMSC/IFlySpeechSynthesizer.h"
#import "iflyMSC/IFlySpeechSynthesizerDelegate.h"
#import "iflyMSC/IFlySpeechConstant.h"
#import "iflyMSC/IFlySpeechUtility.h"
#import "iflyMSC/IFlySetting.h"
配置语音信息!
- (void)configIFlySpeech
{导航信息配置:
[AMapNaviServices sharedServices].apiKey =AMKEY;
管理者
- (void)initNaviManager
{
if (self.naviManager == nil)
{
self.naviManager = [[AMapNaviManager alloc] init];
}
[self.naviManager setDelegate:self];
}
导航视图
- (void)initNaviViewController
{
if (self.naviViewController == nil)
{
self.naviViewController = [[AMapNaviViewController alloc] initWithDelegate:self];
}
[self.naviViewController setDelegate:self];
}
语音
- (void)initIFlySpeech
{
if (self.iFlySpeechSynthesizer == nil)
{
_iFlySpeechSynthesizer = [IFlySpeechSynthesizer sharedInstance];
}
_iFlySpeechSynthesizer.delegate = self;
}
/*!
@brief AMapNaviManager发生错误时的回调函数
@param error 错误信息
*/
- (void)naviManager:(AMapNaviManager *)naviManager error:(NSError *)error;
/*!
@brief naviViewController被展示出来后的回调
@param naviViewController 被展示出来的ViewController
*/
- (void)naviManager:(AMapNaviManager *)naviManager didPresentNaviViewController:(UIViewController *)naviViewController
{
NSLog(@"didPresentNaviViewController");
[self.naviManager startGPSNavi];
}
/*!
@brief 驾车路径规划成功后的回调函数
*/
- (void)naviManagerOnCalculateRouteSuccess:(AMapNaviManager *)naviManager
{
NSLog(@"OnCalculateRouteSuccess");
if (self.naviViewController == nil)
{
[self initNaviViewController];
}
[self.naviManager presentNaviViewController:self.naviViewController animated:YES];
}
/*!
@brief 驾车路径规划失败后的回调函数
@param error 计算路径的错误,error.code参照AMapNaviCalcRouteState
*/
- (void)naviManager:(AMapNaviManager *)naviManager onCalculateRouteFailure:(NSError *)error;
/*!
@brief 导航播报信息回调函数
@param soundString 播报文字
@param soundStringType 播报类型,包含导航播报、前方路况播报和整体路况播报,参考AMapNaviSoundType
*/
- (void)naviManager:(AMapNaviManager *)naviManager playNaviSoundString:(NSString *)soundString soundStringType:(AMapNaviSoundType)soundStringType
{
NSLog(@"playNaviSoundString:{%ld:%@}", (long)soundStringType, soundString);
if (soundStringType == AMapNaviSoundTypePassedReminder)
{
//用系统自带的声音做简单例子,播放其他提示音需要另外配置
AudioServicesPlaySystemSound(1009);
}
else
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
if (soundStringType ==1) {
NSString *str = [NSString stringWithFormat:@"上海喜 泊 客 约 停 车 为您导航:%@",soundString];
[_iFlySpeechSynthesizer startSpeaking:str];
}else{
[_iFlySpeechSynthesizer startSpeaking:soundString];
}
});
}
}
#pragma mark - AManNaviViewController Delegate
- (void)naviViewControllerCloseButtonClicked:(AMapNaviViewController *)naviViewController
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
[_iFlySpeechSynthesizer stopSpeaking];
});
[self.naviManager stopNavi];
[self.naviManager dismissNaviViewControllerAnimated:YES];
}
- (void)naviViewControllerMoreButtonClicked:(AMapNaviViewController *)naviViewController
{
if (self.naviViewController.viewShowMode == AMapNaviViewShowModeCarNorthDirection)
{
self.naviViewController.viewShowMode = AMapNaviViewShowModeMapNorthDirection;
}
else
{
self.naviViewController.viewShowMode = AMapNaviViewShowModeCarNorthDirection;
}
}
- (void)naviViewControllerTurnIndicatorViewTapped:(AMapNaviViewController *)naviViewController
{
[self.naviManager readNaviInfoManual];
}
#pragma mark - iFlySpeechSynthesizer Delegate
- (void)onCompleted:(IFlySpeechError *)error
{
NSLog(@"Speak Error:{%d:%@}", error.errorCode, error.errorDesc);
}