私のアプリからのビデオをUIActivityViewController
と共有しようとしています。 したがって、プロセスは次のようになります。UIActivityIndicatorViewが適切なタイミングで停止しない
- ユーザーが[共有]ボタンをタップしています。
- 私は彼のために私の機能でビデオを用意しなければなりません
saveToShare()
。 - 私はUIActivityIndicatorViewのアニメーションを開始し、
saveToShare()
を起動しています。 saveToShare
から私のコントローラに通知を送信しています。- 私のコントローラのオブザーバが機能
shareVideo()
を起動しています。func videoIsReady() { self.activityIndicator.stopAnimating() self.activityIndicator.isHidden = true let videoName = "NewWatermarkedVideoNew2Share.mov" let exportPath = NSTemporaryDirectory().appending(videoName) let exportUrl = URL(fileURLWithPath: exportPath) let urlData = NSData(contentsOf: exportUrl) if ((urlData) != nil){ let videoLink = exportUrl let objectsToShare = [videoLink] let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil) activityVC.popoverPresentationController?.sourceView = self.view // so that iPads won't crash activityVC.setValue("#myhashtag", forKey: "subject") activityVC.excludedActivityTypes = [UIActivityType.airDrop, UIActivityType.addToReadingList, UIActivityType.assignToContact, UIActivityType.copyToPasteboard, UIActivityType.openInIBooks, UIActivityType.postToTencentWeibo, UIActivityType.postToVimeo, UIActivityType.postToWeibo, UIActivityType.print, UIActivityType.saveToCameraRoll, UIActivityType.postToFlickr, UIActivityType.postToTwitter, UIActivityType(rawValue: "com.apple.reminders.RemindersEditorExtension"), UIActivityType(rawValue: "com.apple.mobilenotes.SharingExtension"),UIActivityType(rawValue: "com.google.Drive.ShareExtension"), UIActivityType(rawValue: "com.apple.mobileslideshow.StreamShareService")] self.present(activityVC, animated: true, completion: { }) } else { print("url is empty...") } }
それは動作しますが、私のUIActivityIndicatorView
を共有ダイアログの前に隠されていませんし、実際にそのダイアログが表示された後、数秒のために働いている:
shareVideo()
はそのように見えます。
ここで何が間違っていますか?
P.S.だから、もし私がDispatchQueue.main.async
にUIActivityIndicatorView
を入れれば問題は解決しますが、なぜこの問題が最初に発生したのか分かりません。
は私表示(場合
videoIsReady()
にメインキューから呼び出される)死者ロックを回避するために、私が開発したこの小さな拡張機能を使用しますあなたがそれを始める場所のコード? – User511スレッドの問題。 – matt
@ User511このコードは非常にシンプルです:self.activityIndicator.startAnimating() – lithium