- 下载Demo包
官方必须注册后,申请完应用信息才能下载Demo,逻辑比较奇怪,这里分享个云盘的Demo [https://pan.baidu.com/s/1c2yrhLI] ,可下载参考
- 下载SDK,添加Framework
同样需要注册后下载
- 添加依赖库
参考官方模板: [[] http://baichuan.taobao.com/docs/doc.htm?spm=a3c0d.7629140.0.0.ntd447&treeId=118&articleId=104173&docType=1 ]
- 开始撸代码了
官方给的OC版的demo,手动撸成swift
Bridging-Header.h 文件 加入OC头文件引用
#import <YWFeedbackFMWK/YWFeedbackKit.h>
核心代码
import UIKit
class FeedbackViewController: UIViewController{
private let feedbackKit = YWFeedbackKit.init(appKey: "23436295")
override func viewDidLoad() {
super.viewDidLoad()
title = "意见反馈"
view.backgroundColor = UIColor.whiteColor()
feedbackKit.extInfo = [
"loginTime": NSDate().description,
"visitPath":"关于->反馈"
]
feedbackKit.customUIPlist = [
"profilePlaceholder": "顶部联系方式",
"chatInputPlaceholder": "输入框里面的内容",
"profileUpdatePlaceholder": "更新联系方式",
"profileUpdateCancelBtnText": "取消更新",
"profileUpdateConfirmBtnText": "确定更新",
"sendBtnText": "发消息",
"sendBtnTextColor": "white",
"sendBtnBgColor": "red",
"hideLoginSuccess": (true),
"profileTitle":"顶部联系方式左侧提示内容",
"profileUpdateTitle":"更新联系方式标题",
"profileUpdateDesc":"更新联系方式文字描述",
"photoFromCamera":"拍摄一张照片",
"photoFromAlbum":"从相册选取",
"photoFromCancel":"取消",
"voiceContent":"点击这里录制语音",
"voiceCancelContent":"滑到这里取消录音",
"voiceReleaseContent":"松开取消录音",
//是否开启录音功能,
//如果不设置,会依据是否包含`YWFeedbackAudioExtentionFMWK.framework`来判断是否开启录音功能
//如果设置为false,无论是否包含`YWFeedbackAudioExtentionFMWK.framework`,都会关闭录音功能
//如果设置为true,且包含`YWFeedbackAudioExtentionFMWK.framework`的情况下,会开启录音功能
"enableAudio":"true"
]
// feedbackKit.makeFeedbackViewControllerWithCompletionBlock { (YWLightFeedbackViewController!, <#NSError!#>) in
// <#code#>
// }
feedbackKit.makeFeedbackViewControllerWithCompletionBlock { (viewController, error) in
if viewController != nil {
viewController.title = "意见反馈"
let nav = UINavigationController.init(rootViewController: viewController)
self.presentViewController(nav, animated: false, completion: {
})
viewController.navigationItem.leftBarButtonItem = UIBarButtonItem.init(image: UIImage.init(named: "icon_back"), style: .Plain, target: self, action: #selector(FeedbackViewController.actionQuitFeedback))
viewController.openURLBlock = { aURLString, aParentController in
let webVC = UIViewController.init()
let webView = UIWebView.init(frame: webVC.view.bounds)
webView.autoresizingMask = [.FlexibleHeight,.FlexibleWidth]
webVC.view.addSubview(webView)
nav.pushViewController(webVC, animated: true)
webView.loadRequest(NSURLRequest.init(URL: NSURL.init(string: aURLString)!))
}
}else {
let title = error.userInfo["msg"] != nil ? error.userInfo["msg"] as! String:"接口调用失败,请保持网络通畅!"
TWMessageBarManager.sharedInstance().showMessageWithTitle(title, description: nil, type: .Error)
}
}
feedbackKit.getUnreadCountWithCompletionBlock { (unreadCount, error) in
if error == nil {
TWMessageBarManager.sharedInstance().showMessageWithTitle("成功获取未读数!", description: String.init(format: "未读数:%@", unreadCount), type: .Success)
}else {
let title = error.userInfo["msg"] != nil ? error.userInfo["msg"] as! String:"接口调用失败,请保持网络通畅!"
TWMessageBarManager.sharedInstance().showMessageWithTitle(title, description: nil, type: .Error)
}
}
}
@objc private func actionQuitFeedback(){
dismissViewControllerAnimated(false) {
self.navigationController?.popViewControllerAnimated(true)
}
}