내 문서 다운로드 옵션이 있습니다. 사용자가 내 앱에서 문서를 다운로드 할 때 모바일에 이미 설치되어있는 iCloud 드라이브에 사용자를 저장해야합니다. 웹과 Xcode 모두에서 iCloud를 구성했지만 문제는 파일을 iCloud 드라이브에 올바르게 복사 할 수 없다는 것입니다. 파일이 성공적으로 다운로드되었으며 iCloud로 이동했지만 파일이 iCloud 드라이브 앱에 표시되지 않습니다. 여기에 내 아이 클라우드 저장 코드iOS Swift 3 파일을 iCloud 드라이브에 프로그램 방식으로 복사
<key>NSUbiquitousContainers</key>
<dict>
<key>iCloud.MyAppBundleIdentifier</key>
<dict>
<key>NSUbiquitousContainerIsDocumentScopePublic</key>
<true/>
<key>NSUbiquitousContainerName</key>
<string>iCloudDriveDemo</string>
<key>NSUbiquitousContainerSupportedFolderLevels</key>
<string>Any</string>
</dict>
</dict>
: 그리고 가장 유용한 기사의
func DownloadDocumnt()
{
print("Selected URL: \(self.SelectedDownloadURL)")
let fileURL = URL(string: "\(self.SelectedDownloadURL)")!
let documentsUrl:URL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first as URL!
let destinationFileUrl = documentsUrl.appendingPathComponent("Libra-\(self.SelectedDownloadFileName)")
let sessionConfig = URLSessionConfiguration.default
let session = URLSession(configuration: sessionConfig)
let request = URLRequest(url:fileURL)
let task = session.downloadTask(with: request) { (tempLocalUrl, response, error) in
if let tempLocalUrl = tempLocalUrl, error == nil
{
if let statusCode = (response as? HTTPURLResponse)?.statusCode
{
print("Successfully downloaded. Status code: \(statusCode)")
}
do
{
if(FileManager.default.fileExists(atPath: destinationFileUrl.path))
{
try FileManager.default.removeItem(at: destinationFileUrl)
try FileManager.default.copyItem(at: tempLocalUrl, to: destinationFileUrl)
}
else
{
try FileManager.default.copyItem(at: tempLocalUrl, to: destinationFileUrl)
}
if let iCloudDocumentsURL = FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("Documents")
{
if(!FileManager.default.fileExists(atPath: iCloudDocumentsURL.path, isDirectory: nil))
{
try FileManager.default.createDirectory(at: iCloudDocumentsURL, withIntermediateDirectories: true, attributes: nil)
}
}
let iCloudDocumentsURL = FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("Documents").appendingPathComponent("Libra-\(self.SelectedDownloadFileName)")
if let iCloudDocumentsURL = iCloudDocumentsURL
{
var isDir:ObjCBool = false
if(FileManager.default.fileExists(atPath: iCloudDocumentsURL.path, isDirectory: &isDir))
{
try FileManager.default.removeItem(at: iCloudDocumentsURL)
try FileManager.default.copyItem(at: tempLocalUrl, to: iCloudDocumentsURL)
}
else
{
try FileManager.default.copyItem(at: destinationFileUrl, to: iCloudDocumentsURL)
}
}
}
catch (let writeError)
{
print("Error creating a file \(destinationFileUrl) : \(writeError)")
}
}
else
{
print("Error took place while downloading a file. Error description");
}
}
task.resume()
}
또는 파인더)? –
@ JohnD. 아니, 다른 곳에서는 나타나지 않습니다. 그러나 설정 -> 저장소 및 iCloudUsage -> iCloud 관리 설정을 통해 확인할 수 있습니다. –