gpt4 book ai didi

ios - 如何使用alertcontroller添加警报消息?

转载 作者:行者123 更新时间:2023-11-30 10:59:45 25 4
gpt4 key购买 nike

我正在使用 Xcode 9.3.1 Swift 4 开发一个开源应用程序。有一个播放按钮。当用户单击播放按钮时,音频文件会在开始播放之前自动下载。我想添加一条提醒消息,提醒用户,显示文件大小,并让他接受或不继续下载。

这是我的audiobarview.xib代码:

import GenericDataSources
import QueuePlayer
import UIKit

internal protocol AdvancedAudioOptionsViewControllerDelegate : AnyObject {
internal func advancedAudioOptionsViewController(_ controller: AdvancedAudioOptionsViewController, finishedWith options: AdvancedAudioOptions)
}

internal class AdvancedAudioOptionsViewController : UIViewController, UIGestureRecognizerDelegate {
weak internal var delegate: AdvancedAudioOptionsViewControllerDelegate?

@IBOutlet weak internal var tableView: UITableView!
@IBOutlet weak internal var contentView: UIView!
@IBOutlet weak internal var bottomConstraint: NSLayoutConstraint!
@IBOutlet weak internal var navigationBar: UINavigationBar!

lazy internal var playButton: UIButton { get set }

internal init(options: AdvancedAudioOptions)

required internal init?(coder aDecoder: NSCoder)

override internal func viewDidLoad()
override internal func viewDidAppear(_ animated: Bool)
override internal func viewDidLayoutSubviews()

@IBAction internal func playButtonTapped(_ sender: Any)
@IBAction internal func dismissView(_ sender: Any)

internal func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool
}

extension UIView {
internal func round(corners: UIRectCorner, radius: CGFloat)
}

这是audiofilesdownloader.swift代码:

import BatchDownloader
import PromiseKit

class AudioFilesDownloader {
let audioFileList: QariAudioFileListRetrieval
let downloader: DownloadManager
let ayahDownloader: AnyInteractor<AyahsAudioDownloadRequest, DownloadBatchResponse>

private var response: DownloadBatchResponse?

init(audioFileList: QariAudioFileListRetrieval,
downloader: DownloadManager,
ayahDownloader: AnyInteractor<AyahsAudioDownloadRequest, DownloadBatchResponse>) {
self.audioFileList = audioFileList
self.downloader = downloader
self.ayahDownloader = ayahDownloader
}

func cancel() {
response?.cancel()
response = nil
}

func needsToDownloadFiles(qari: Qari, range: VerseRange) -> Bool {
let files = filesForQari(qari, range: range)

return !files.filter { !FileManager.documentsURL.appendingPathComponent($0.destinationPath).isReachable }.isEmpty
}

func getCurrentDownloadResponse() -> Promise<DownloadBatchResponse?> {
if let response = response {
return Promise(value: response)
} else {
return downloader.getOnGoingDownloads().then { batches -> DownloadBatchResponse? in
let downloading = batches.first { $0.isAudio }

self.createRequestWithDownloads(downloading)

return self.response
}
}
}

func download(qari: Qari, range: VerseRange) -> Promise<DownloadBatchResponse?> {
return ayahDownloader
.execute(AyahsAudioDownloadRequest(range: range, qari: qari))
.then(on: .main) { responses -> DownloadBatchResponse? in
// wrap the requests
self.createRequestWithDownloads(responses)

return self.response
}
}

private func createRequestWithDownloads(_ batch: DownloadBatchResponse?) {
guard let batch = batch else { return }

response = batch
response?.promise.always { [weak self] in
self?.response = nil
}
}

func filesForQari(_ qari: Qari, range: VerseRange) -> [DownloadRequest] {
return audioFileList.get(for: qari, range: range).map {
DownloadRequest(url: $0.remote, resumePath: $0.local.stringByAppendingPath(Files.downloadResumeDataExtension), destinationPath: $0.local)
}
}
}

最佳答案

假设您将文件大小作为变量filesize

Swift 4:

let alert = UIAlertController(title: "Proceed with download?", message: "File size: \(filesize)", preferredStyle: .alert)

alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: {(alert: UIAlertAction!) in
// Leave empty, dismisses the alert
}))

alert.addAction(UIAlertAction(title: "Download Song", style: .default, handler: {(alert: UIAlertAction!) in
// Code to download song
}))

self.present(alert, animated: true, completion: nil)

关于ios - 如何使用alertcontroller添加警报消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53516625/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com