前提・実現したいこと
iCloudからのデータのダウンロードが完了したことを通知で取得したい
ここに質問の内容を詳しく書いてください。
機種変更時にアプリのデータをiCloudからダウンロードしてからデータを読み出すプログラムを作っています。
iCloudからダウンロードを開始する関数"startDownloadingUbiquitousItem"を実行したのですが
ダウンロードが完了した通知の取得がわかりません。
"ダウンロードの完了"を通知するNotificationCenterのnameはありますでしょうか?
今はタイマーで5秒毎に確認しているのですが、もっと良い形があると思いましてお知恵をいただけますようお願いいたします
発生している問題・エラーメッセージ
エラーメッセージはありませんがきれいなコードではないと思っています
該当のソースコード
func startDownLoad(url: URL!){
let fileManager = FileManager.default
do {
try fileManager.startDownloadingUbiquitousItem(at: url!)
print("readiCloudContainer:1:ダウンロード開始")
url1 = url
//タイマー開始
self.timer = Timer.scheduledTimer(timeInterval: 5, target: self, selector: #selector(timerUpdate), userInfo: nil, repeats: true)
}catch let err{
print("readiCloudContainer:1:(err.localizedDescription)")
}
}
@objc func timerUpdate(){
do{
let status = try url1!.resourceValues(forKeys: [.ubiquitousItemDownloadingStatusKey])
if status.ubiquitousItemDownloadingStatus == .current{
print("ダウンロード完了")
self.timer?.invalidate()
}else{
print("ダウンロード中:(j)")
}
}catch let error{
print("ダウンロードエラー:(error)")
}
}
SWIFT
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー