欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

Swift

當(dāng)前位置:主頁 > 軟件編程 > Swift >

Swift如何為設(shè)置中心添加常用功能

來源:本站原創(chuàng)|時間:2020-01-11|欄目:Swift|點擊: 次

前言

在我們開發(fā)所有的應(yīng)用中,通常會提供包含多項功能的設(shè)置中心。這些功能可以包括,給用戶推薦自己的其他作品、邀請用戶好評、提供反饋通道、邀請用戶分享應(yīng)用、打開官網(wǎng)或某些其他地址。 這些功能雖然用戶使用頻率不高,但對于應(yīng)用的設(shè)置中心是必備的。

1.跳轉(zhuǎn)到AppStore,邀請好評或推薦其他應(yīng)用

2.提供系統(tǒng)郵件反饋通道

3.調(diào)取系統(tǒng)分享功能分享應(yīng)用

4.在應(yīng)用內(nèi)打開網(wǎng)頁,實現(xiàn)官方網(wǎng)址、應(yīng)用更新說明或打開其他網(wǎng)址

通常設(shè)置中心由TableView或CollectionView創(chuàng)建,在didSelectRowAt中添加不同的點擊反饋即可,這里就不再描述。

一、跳轉(zhuǎn)到AppStore

應(yīng)用內(nèi)跳轉(zhuǎn)到AppStore可以通過設(shè)置對應(yīng)的應(yīng)用地址即可,因此可以跳轉(zhuǎn)到其他應(yīng)用界面實現(xiàn)推薦應(yīng)用,也可以跳轉(zhuǎn)到自身應(yīng)用的地址邀請用戶好評。OneX系列產(chǎn)品都擁有推薦和評價的入口,兩種入口的實現(xiàn)方式也都是一樣的。 在不同的情況下我們只需要改變urlString末尾的ID即可,當(dāng)讓也可以封裝在某一個函數(shù)中,通過參數(shù)進(jìn)行改變具體的跳轉(zhuǎn)地址。

let urlString = "itms-apps://itunes.apple.com/app/id1250290965"
if let url = URL(string: urlString) {
 //根據(jù)iOS系統(tǒng)版本,分別處理
 if #available(iOS 10, *) {
 UIApplication.shared.open(url, options: [:],
     completionHandler: {
     (success) in
 })
 } else {
 UIApplication.shared.openURL(url)
 }
}

二、郵件反饋功能

第一,需要導(dǎo)入框架MessageUI.framework,在項目設(shè)置Build Phases的Link Binary With Libraries中添加MessageUI.framework。 第二,在使用郵件反饋功能的頁面文件中導(dǎo)入頭文件import MessageUI。 第三,給所在Controller加上協(xié)議MFMailComposeViewControllerDelegate。

完成以上步驟之后,我們就可以開始寫具體的使用代碼了。 發(fā)送反饋郵件時,為了方便我們收到郵件時辨別是用戶發(fā)來的反饋郵件,同時了解用戶的系統(tǒng)、版本等信息,我們在發(fā)送函數(shù)中設(shè)置好標(biāo)題與默認(rèn)正文。 mailComposeVC.setToRecipients中添加收件郵箱地址,mailComposeVC.setSubject中添加郵件標(biāo)題,mailComposeVC.setMessageBody設(shè)置正文內(nèi)容。

//郵件發(fā)送函數(shù)
func configuredMailComposeViewController() -> MFMailComposeViewController {

 let mailComposeVC = MFMailComposeViewController()
 mailComposeVC.mailComposeDelegate = self

 //獲取設(shè)備信息
 let deviceName = UIDevice.current.name
 // let deviceModel = UIDevice.current.model
 let systemVersion = UIDevice.current.systemVersion
 let deviceUUID = UIDevice.current.identifierForVendor?.uuidString

 //獲取APP信息
 let infoDic = Bundle.main.infoDictionary
 // 獲取App的版本號
 let appVersion = infoDic?["CFBundleShortVersionString"] ?? "appVersion"
 // 獲取App的build版本
 let appBuildVersion = infoDic?["CFBundleVersion"] ?? "appBuildVersion"
 // 獲取App的名稱
 let appName = infoDic?["CFBundleDisplayName"] ?? "OneClock"

 //設(shè)置郵件地址、主題及正文
 mailComposeVC.setToRecipients(["<xdehang@gmail.com>"])
 mailComposeVC.setSubject("OneScreen "+String(describing: appVersion)+" - "+NSLocalizedString("FeedBack Mail From", comment: "FeedBack Mail From")+" "+deviceName)

 let content:String = "\n \n \n \n Device:\(deviceName)\n System:\(systemVersion)\n App Version:\(String(describing: appVersion))"

 mailComposeVC.setMessageBody(NSLocalizedString("<Start To Write Mail>", comment: "<Start To Write Mail>")+content, isHTML: false)
 return mailComposeVC
}

再需要添加郵件系統(tǒng)提示和郵件發(fā)送檢測。

//郵件系統(tǒng)提示
func showSendMailErrorAlert() {
 let sendMailErrorAlert = UIAlertController(title: NSLocalizedString("Unable To Send", comment: "Unable To Send"), message: NSLocalizedString("Your device has not been set up, please set in the mail application and then try to send.", comment: "Your device has not been set up, please set in the mail application and then try to send."), preferredStyle: .alert)
 sendMailErrorAlert.addAction(UIAlertAction(title: NSLocalizedString("Confirm", comment: "Confirm action title"), style: .default) { _ in })
 self.present(sendMailErrorAlert, animated: true){}

}
//郵件發(fā)送檢測
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {

 switch result.rawValue {
 case MFMailComposeResult.cancelled.rawValue:
 print("取消發(fā)送")
 case MFMailComposeResult.sent.rawValue:
 print("發(fā)送成功")
 default:
 break
 }
 self.dismiss(animated: true, completion: nil)
}

最后我們在調(diào)用郵件反饋的地方,需要先判斷是否能夠發(fā)送,如果不能發(fā)送通過提示信息告訴用戶失敗原因,如果可以發(fā)送將成功調(diào)取發(fā)送窗口。 在需要郵件反饋的地方:

if MFMailComposeViewController.canSendMail() {
 //注意這個實例要寫在if block里,否則無法發(fā)送郵件時會出現(xiàn)兩次提示彈窗(一次是系統(tǒng)的)
 let mailComposeViewController = configuredMailComposeViewController()
 self.present(mailComposeViewController, animated: true, completion: nil)

} else {
 self.showSendMailErrorAlert()
}

三、系統(tǒng)分享功能

分享前,我們需要設(shè)置好分享的信息:標(biāo)題、圖片、鏈接。

var webUrl:String = "https://itunes.apple.com/cn/app/id1355476695"
var urlTitle:String = "OneScreen"
var urlImage:UIImage = #imageLiteral(resourceName: "onescreen_icon")

這里使用了var,是為了在特殊情況下改變他們的值,具體的調(diào)用方式如下:

let shareVC:UIActivityViewController = UIActivityViewController(activityItems: [self.urlTitle,self.urlImage,self.webUrl], applicationActivities: nil)

self.present(shareVC, animated: true, completion: {
 print("shareVC success")
})

四、打開某些網(wǎng)址

打開網(wǎng)址可以實現(xiàn)“官方網(wǎng)址”、“應(yīng)用更新說明”功能,更新說明我們可以通過更新Web內(nèi)容快速高速用戶更新列表。如果你的應(yīng)用需要比較多的教程,也可以通過網(wǎng)頁的形式展現(xiàn)。為了方便用戶反饋,我通常會增加一個微博入口,讓用戶打開微博地址快速與我聯(lián)系進(jìn)行反饋。

這個功能我們需要創(chuàng)建一個承載網(wǎng)頁內(nèi)容的Web頁面,因此需要先添加帶有WebView的Controller。 在其他頁面打開Web時,通過傳遞參數(shù)來告訴WebView具體呈現(xiàn)哪一個網(wǎng)址。

例如在OneDay的WebViewController中:

override func viewDidLoad() {
 super.viewDidLoad()

 // Do any additional setup after loading the view.
 switch webIndex {
 case 0:
  self.urlString = "https://weibo.com/bujidehang"
 case 1:
  self.urlString = "http://www.ohweonline.com/oneday"
 case 2:
  self.urlString = "http://www.ohweonline.com/oneday/updateCN.html"
 case 3:
  self.urlString = "http://www.ohweonline.com/oneday/updateEN.html"
 default:
  self.urlString = "http://www.ohweonline.com/oneday"
 }

 let urlobj = URL(string:self.urlString)
 let request = URLRequest(url:urlobj!)
 webView.loadRequest(request)
 print(webView.isLoading)
}

在設(shè)置頁面中,我們開始打開Web:

print("to webview")
self.webIndex = 1
self.performSegue(withIdentifier: "viewWebView", sender: self)

將WebIndex傳遞給WebViewController,以方便判斷具體的網(wǎng)址。

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
 if segue.identifier == "viewWebView"{
  let dest = segue.destination as! WebViewController
  dest.webIndex = self.webIndex
 }
}

這樣就實現(xiàn)了所有相關(guān)網(wǎng)址的打開。實際在網(wǎng)頁加載頁面中還有一些特性和功能,將在下一期文章中詳細(xì)說明。 打開網(wǎng)址

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,如果有疑問大家可以留言交流,謝謝大家對我們的支持。

上一篇:Swift Json實例詳細(xì)解析

欄    目:Swift

下一篇:Swift中排序算法的簡單取舍詳解

本文標(biāo)題:Swift如何為設(shè)置中心添加常用功能

本文地址:http://mengdiqiu.com.cn/a1/Swift/11960.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有