SCENARIOGCD:連続したダウンロード呼び出しを作成する。 ONE
アプリのダウンロードユーザーのサブスクリプションを一つずつBY ONE。この呼び出しは、複数の場所で行われます(別のネットワーク呼び出しの後に完了ブロックで、UIAlertController
からのボタンを押すと)。ロジックはすべてのサブスクリプションをダウンロードすることです.1つのサブスクリプションのダウンロードが終了すると、すべてのダウンロードが完了してからSVProgressHUD
が終了するまで次のサブスクリプションのダウンロードが終了します。このコードは、Xcodeからビルドして実行するときに効果的です。我々はIPAを構築し、当社の顧客に送信する場合でも、このロジックは、ストールのいくつかの並べ替えを作成し、SVProgressHUD
アラートが回転し続ける:
我々のアプリケーションがダウンロードコンテンツの周りに集中しているので、これは大きな問題ですサブスクリプションから。
私はそれをアーカイブしてビルドした後にこのロジックがストールするのですが、ではなく、をビルドしてXcodeから実行すると、
以下に、コード:
// Making the call
DispatchQueue.main.async {
DGWebService().syncUserSubscribedContent {
DispatchQueue.main.async {
self.finishLogin()
}
}
}
// Sequentially going through each subscription and downloading them
func syncUserSubscribedContent(completion: @escaping Constants.WebService.ContentCompletion) {
let subscriptions = MPTUser.sharedUser.getSubscriptionsForDownload()
DispatchQueue.global().async {
if subscriptions.count > 0 {
var index:Int = 0
var t = subscriptions.count
var downloading: Bool = false
while t != 0 {
if downloading == false {
downloading = true
if index < 0 {
index = 0
}
if index > subscriptions.count - 1 {
index = subscriptions.count - 1
}
if index <= subscriptions.count {
let subscription = subscriptions[index]
if subscription.didDownloadContent == false {
if let subscriptionID = subscription.subscriptionID {
DispatchQueue.main.async {
SVProgressHUD.show(withStatus: "Downloading Documents\nfor\n\(subscription.functionalGroupName!)\n\(index+1) of \(subscriptions.count)")
}
self.getUserSubscribedContent(subscriptionID: subscriptionID, completion: { (success) in
subscription.didDownloadContent = true
index += 1
t -= 1
downloading = false
})
}
else {
index += 1
t -= 1
downloading = false
}
}
}
else {
index += 1
t -= 1
downloading = false
}
}
}
}
completion()
}
}
self.getUserSubscribedContent
は、コンテンツをダウンロードし、バックブロックで完了を送る機能です。
誰かが私をここで助けることができたら、それは非常に感謝します。
あなたの例ではたくさんのコードがあるようです。バックグラウンドスレッド(ダウンロードを同期させる)で 'DispatchGroup'を実行し、ダウンロードごとにメインスレッドのラベルを更新してみましたか? –
こんにちは@ILikeTau。これは有望な提案です。あなたが私にコードの例を与えることができれば、それは非常に高く評価されるでしょう。 –