[技術(shù)文檔][技術(shù)中心][iOS部][114啦]搜索結(jié)果分享

需求說(shuō)明

1、搜索結(jié)果支持分享,生成H5頁(yè)面展示。
2、分享出去的H5頁(yè)面可以打開(kāi)114啦的搜索界面。

需求地址

http://192.168.1.75/114la/220/114la_220/#g=1&p=2_2_%E6%90%9C%E7%B4%A2_%E6%B5%8F%E8%A7%88%E4%BA%A4%E4%BA%92

相關(guān)邏輯及代碼

在請(qǐng)求綜合搜索時(shí),會(huì)返回一個(gè)用于分享的URL。
該url有固定格式: http://114larc.com/p/search?q=1 ->第一個(gè)q= 后面的都是搜索的關(guān)鍵詞。
因?yàn)樗阉鳑](méi)有相關(guān)經(jīng)驗(yàn)時(shí)也會(huì)返回該字段,所以客戶端添加了判斷,
如果沒(méi)有相關(guān)內(nèi)容則不顯示分享搜索結(jié)果的選項(xiàng)。

        if !json["data"]["share"].stringValue.isEmpty && tempDatas.count > 0
                    && self.datas?.last?.type != .share {
                        let shareModel = SearchGroupModel(SearchGroupType.share)
                        shareModel.searchDatas = [SearchCellModel(keyword: json["data"]["share"].stringValue)]
                        self.datas?.append(shareModel)
                    }

當(dāng)點(diǎn)擊分享搜索結(jié)果時(shí)則自定義分享顯示的信息,不自定義的話會(huì)獲取當(dāng)前打開(kāi)的頁(yè)面相關(guān)的url和title。

case .share:
                guard let model = groupModel.searchDatas?[indexPath.row] else { return }
                PageViewManager.showShare(model.keyWord, shareText: "114啦 - 搜索\"\(String(describing: urlBarView!.addressTextField.text!))\"")
                return

以上是分享出去的邏輯。


經(jīng)過(guò)確定,114啦中是不用打開(kāi)該分享出去的H5頁(yè)面的。
當(dāng)識(shí)別出http://114larc.com/p/search?q=(關(guān)鍵詞)鏈接時(shí),
或者第三方調(diào)用"oof.browser://openlink/?search/word=(關(guān)鍵詞)",
則使用原生UI打開(kāi)搜索界面并進(jìn)行搜索。

if url.absoluteString.hasPrefix("oof.browser://openlink/?search/word=") {//搜索用114啦打開(kāi)。。去除所有界面。打開(kāi)搜索界面。
            let str = url.absoluteString.replacingOccurrences(of: "oof.browser://openlink/?search/word=", with: "")
            if let strd = str.ud_UrlDecoded() {
                if didWebFinishLoaded == true {
                    if let navC = window?.rootViewController as? UINavigationController {
                        let mainViewController = navC.viewControllers.first as! MainViewController
                        mainViewController.openSearchView(searchKey: strd)
                    }
                }else{
                    openSearchKey = strd
                }
            }
            return false
        }
func openSearchView(searchKey: String) {
        resetMainViewController(false)
        removePicBrowser()
        showSearchView()
        let key = searchKey.removingPercentEncoding ?? searchKey
        urlBarView?.addressTextField.text = key
        searchViewManager.textFieldText = key
    }
//需要將各種彈層移除。再新建標(biāo)簽頁(yè)打開(kāi)。。 分享彈層         菜單彈層     搜索界面。。
    func resetMainViewController(_ hideSearch: Bool = true) {
        var isViaUserCommon = true//默認(rèn)用戶直接點(diǎn)擊常用欄,直接跳轉(zhuǎn)到這個(gè)界面

        if let _ = self.presentedViewController as? UINavigationController {
            isViaUserCommon = false
        }
        if let _ = self.presentedViewController as? TabManageViewController {
            self.dismiss(animated: true, completion: nil)
        }
        if isViaUserCommon {
            self.navigationController?.popToRootViewController(animated: false)
        } else {
            self.navigationController?.dismiss(animated: false, completion: nil)
        }
        if let urlbarview = urlBarView , hideSearch == true {//收起搜索界面。
            urlbarview.cancelBtnClicked(urlbarview.cancelButton)
        }
    }
移除蓋在mainview上的控制器
    func removePicBrowser() {
        var currentVc : UIViewController!
        if let newNav = self.presentedViewController as? UINavigationController {
            currentVc = newNav.viewControllers.last!
        } else {
            currentVc = self.navigationController?.viewControllers.last ?? self
        }
        
        for vc in currentVc.childViewControllers {
            if let picVc = vc as? PicBrowser {
                picVc.btnClicked(picVc.cancelBtn)
            }
            if let picVc = vc as? PictureBrowser {
                picVc.btnClicked(picVc.cancelBtn)
            }
        }
        
        if let window = UIApplication.shared.keyWindow {
            for view in window.subviews {
                if let menu = view as? YYWMenuView {
                    menu.disMiss()
                }
                if let action = view as? ActionView {
                    action.disMiss()
                }
            }
        }
    }

在PageView的loadRequest(_ request: URLRequest)中攔截搜索的url。使用原生UI打開(kāi)。

if strd.contains("114larc.com/p/search?q=") || strd.contains("114la.com/p/search?q=") {//搜索的界面
                strd = strd.substring(from: strd.range(of: ".com/p/search?q=")!.upperBound)
                mainViewController().openSearchView(searchKey: strd)
                return
            }

還有如果在搜索框輸入114la.com/p/search?q=(關(guān)鍵詞) 再點(diǎn)擊鍵盤(pán)的前往按鈕,
則將關(guān)鍵詞截取出來(lái)放在搜索框中進(jìn)行搜索。
期間會(huì)有對(duì)url的encode與decode操作,確保關(guān)鍵詞正確。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 需求說(shuō)明 1、首頁(yè)進(jìn)入顯示搜索歷史,網(wǎng)頁(yè)進(jìn)入對(duì)關(guān)鍵詞進(jìn)行聯(lián)想搜索。2、搜索需要用web打開(kāi)都統(tǒng)一新建標(biāo)簽頁(yè)打開(kāi),加...
    Zongzi_599閱讀 657評(píng)論 0 0
  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,030評(píng)論 25 709
  • 1 我剛趕到一品餐廳這個(gè)地方,心里就產(chǎn)生了一種不祥的預(yù)感。 老羅找我說(shuō)事兒的嚴(yán)重程度完全決定了餐廳的檔次,像這種人...
    果仁小姐閱讀 4,594評(píng)論 115 131
  • 上山坡路不易行, 林木灌溉夏日涼。 舍寒窯中望無(wú)邊, 景秀河山造福人。 ...
    龐小慧閱讀 182評(píng)論 0 2
  • 濟(jì)南坊間有句俚語(yǔ),叫“誰(shuí)過(guò)年還不吃頓餃子”。意思是說(shuō):人生若沒(méi)有開(kāi)疆拓土,過(guò)五關(guān),斬六將之類的豐功偉績(jī),大可不必對(duì)...
    漠漠無(wú)語(yǔ)閱讀 607評(píng)論 3 3

友情鏈接更多精彩內(nèi)容