2017-05-12 19 views
3

내 문서 다운로드 옵션이 있습니다. 사용자가 내 앱에서 문서를 다운로드 할 때 모바일에 이미 설치되어있는 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() 
    } 
+0

또는 파인더)? –

+0

@ JohnD. 아니, 다른 곳에서는 나타나지 않습니다. 그러나 설정 -> 저장소 및 iCloudUsage -> iCloud 관리 설정을 통해 확인할 수 있습니다. –

답변

4

한 나는이 문제는 다음 링크에서했다 가졌다 :

여기 내 노력 코드 Technical Q&A QA1893 Updating the metadata of iCloud containers for iCloud Drive

또한 info.plist 항목을 삭제하고 다시 추가했습니다. 매우 조심하십시오. 그것이 작동하는 것처럼 보입니다. 나는 원래 온라인 자원에서 항목을 복사하여 붙여 넣었습니다. 키가 정확하게 정확하지 않거나 숨겨진 문자가 포함되어 인식되지 않게 된 것 같습니다. 파일 앱의 iCloud에 컨테이너 내부에 저장되어있는 경우

Enabling Document Storage in iCloud Drive

2

당신은 직접 아이 클라우드 드라이브 앱에서 파일을 볼 수 없습니다. 당신이 UbiquityContainerIdentifier 경로와 아이 클라우드에 파일을 저장하면

let iCloudDocumentsURL = FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("Documents") 

, 그것은 당신의 앱의 iCloud에 컨테이너 내부의 파일을 저장합니다. 앱의 컨테이너가 보호되어있어 iCloud 드라이브에서 직접 볼 수 없습니다.

하지만 우리는 설정을 통해 볼 수 -> iCloud를 - -> 아이 클라우드 -> 관리 저장 - 당신의 iCloud를 클릭>> 당신의 앱 이름 -> 당신의 앱 폴더 (아이 클라우드 드라이브에서 응용 프로그램을 표시합니까