在线客服软件海豚客服支持安卓和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了解或联系技术人员解答。