接入讯飞SDK及参数设置
简要描述
主要协助云上越秀App对接云学堂.AI智能教练H5过程中,为了减少H5在App内的兼容性,iOS接入WKwebview;
iOS接入WKWebView
iOS平台接入WKWebView的示例代码:
#import <WebKit/WebKit.h> // 导入WebKit框架@property (nonatomic) WKWebView *webView; // 声明webView属性/// 懒加载webView的属性- (WKWebView *)webView {if (_webView == nil) {_webView = [[WKWebView alloc]init];_webView.navigationDelegate = self;_webView.translatesAutoresizingMaskIntoConstraints = NO;}return _webView;}/// 获取webView的约束- (NSArray <NSLayoutConstraint *> *)getBindEdgesConstraintsForView:(UIView *)view {CGRect statusFrame = [PHAIUtils statusBarFrame];CGFloat statusHeight = statusFrame.size.height;CGFloat navigationBarHeight = self.navigationController.navigationBar.frame.size.height;NSLayoutConstraint *top = [NSLayoutConstraint constraintWithItem:viewattribute:NSLayoutAttributeToprelatedBy:NSLayoutRelationEqualtoItem:self.viewattribute:NSLayoutAttributeTopmultiplier:1constant:(statusHeight + navigationBarHeight)];NSLayoutConstraint *bottom = [NSLayoutConstraint constraintWithItem:viewattribute:NSLayoutAttributeBottomrelatedBy:NSLayoutRelationEqualtoItem:self.viewattribute:NSLayoutAttributeBottommultiplier:1constant:0];NSLayoutConstraint *leading = [NSLayoutConstraint constraintWithItem:viewattribute:NSLayoutAttributeLeadingrelatedBy:NSLayoutRelationEqualtoItem:self.viewattribute:NSLayoutAttributeLeadingmultiplier:1constant:0];NSLayoutConstraint *traling = [NSLayoutConstraint constraintWithItem:viewattribute:NSLayoutAttributeTrailingrelatedBy:NSLayoutRelationEqualtoItem:self.viewattribute:NSLayoutAttributeTrailingmultiplier:1constant:0];return @[top, bottom, leading, traling];}/// 添加WKWebView和约束[self.view addSubview:self.webView];[self.view addConstraints:[self getBindEdgesConstraintsForView:self.webView]];
WKWebView页面的返回处理方法:
- (void)backAction:(UIButton *)sender {PHAILog(@"点击了返回按钮。");GloablLog(@"点击了返回按钮。");if ([self.webView canGoBack]) {[self.webView goBack];} else {[self.navigationController.presentingViewController dismissViewControllerAnimated:YES completion:^{if (PHAISparring.refreshH5Block) {PHAISparring.refreshH5Block(YES);}}];if (self.backBlock) {self.backBlock();}}}