在线客服软件海豚客服APP接入方法二:IOS篇

2 篇文章 0 订阅
1 篇文章 0 订阅

在线客服软件海豚客服支持安卓和IOS应用接入,本篇分享IOS系统APP应用接入方法分享:

选择【系统接入】-【APP】-【新增渠道】

设置【新增渠道–渠道名称–确定】,部署配置,复制链接,并由APP开发工作人员在APP上进行配置。
在这里插入图片描述
iOS代码如下:
1、新建一个viewController类,导入头文件WebKit,在viewDidLoad方法中添加webView,地址指向海豚客服的h5页面。

OC代码:

#import "ViewController.h"
#import <WebKit/WebKit.h>
@interface ViewController() <WKNavigationDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
  [super viewDidLoad];
  // Do any additional setup after loading the view.
  WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
  WKWebView *webView = [[WKWebView alloc] initWithFrame:self.view.bounds configuration:configuration];
  webView.navigationDelegate = self;
  [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://h5chat.17j.club/#/chat?appId=h5000001"]]];
  [self.view addSubview:webView];
}
#pragma mark - WKNavigationDelegate
- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler {
  if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
    NSURLCredential *credential = [[NSURLCredential alloc] initWithTrust:challenge.protectionSpace.serverTrust];
    completionHandler(NSURLSessionAuthChallengeUseCredential, credential);
  }
}
@end

swift代码:

import UIKit
import WebKit
class ViewController: UIViewController, WKNavigationDelegate {
  override func viewDidLoad() {
    super.viewDidLoad()

    let configuration = WKWebViewConfiguration()
    let webView = WKWebView(frame: view.bounds, configuration: configuration)
    webView.navigationDelegate = self;
    webView.load(URLRequest(url: URL(string: "https://h5chat.17j.club/#/chat?appId=h5000001")!))
    view.addSubview(webView)
  }

  func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
    if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {
      let credential = URLCredential(trust: challenge.protectionSpace.serverTrust!)
      completionHandler(.useCredential, credential)
    }
  }
}

2、在工程info.plist文件中,增加隐私权限:

Privacy - Camera Usage Description 需要访问您的相机

Privacy - Photo Library Usage Description 需要访问您的相册

Privacy - Photo Library Additions Usage Description 需要访问您的相册

更多在线客服软件设置问题关注公众号海豚应答或点击官方网站www.17j.club了解或联系技术人员解答。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值