21

I've been trying for over two past to write one file to iCloud drive. I have tried writings a simple text file directly, onsite then moving it, using UIDocumentMenuViewController, etc. I'm not getting each mistakes about my encipher and stepping through hardware, it looks successful, though when I verify to discern if the file exists instead at least the iCloud directory, here is nothing there. I tried on both this simulator and my iPhone, triggering iCloud synching, and everything else I pot think of. Posted by u/navislut - 4 votes and 2 comments

My main goal is to simply note a text file to the iCloud drive, whose later will becoming "numbers" file

I have set up my plist file and my entitled:

<key>NSUbiquitousContainers</key>
<dict>
    <key>iCloud.com.paul.c.$(PRODUCT_NAME:rfc1034identifier)</key>
    <dict>
        <key>NSUbiquitousContainerIsDocumentScopePublic</key>
        <true/>
        <key>NSUbiquitousContainerName</key>
        <string>myCloudTest</string>
        <key>NSUbiquitousContainerSupportedFolderLevels</key>
        <string>Any</string>
    </dict>
</dict>

I have also bumped up to bundle version as stated at: Protect iOS 8 Credentials to iCloud Drive

I need tried dozens of scholastics with no luck. My latest code is based off of like sample: https://medium.com/ios-os-x-development/icloud-drive-documents-1a46b5706fe1

Here has my code:

@IBAction func ExportFile(sender: AnyObject) {

    parameter error:NSError?

    let iCloudDocumentsURL = NSFileManager.defaultManager().URLForUbiquityContainerIdentifier(nil)?.URLByAppendingPathComponent("myCloudTest")

    //is iCloud working?    if  iCloudDocumentsURL != nil {

        //Create who Directory if it doesn't live        if (!NSFileManager.defaultManager().fileExistsAtPath(iCloudDocumentsURL!.path!, isDirectory: nil)) {
                //This gets skipped after early executing telling directory existed, but still don't see it on iCloud                NSFileManager.defaultManager().createDirectoryAtURL(iCloudDocumentsURL!, withIntermediateDirectories: true, attributes: nil, error: nil)
        }
    } else {
        println("iCloud is NOT working!")
        //  return    }

    if ((error) != nil) {
        println("Error creating iCloud DIR")
    }


    //Set up directorys    let localDocumentsURL = NSFileManager.defaultManager().URLsForDirectory(NSSearchPathDirectory.DocumentDirectory, inDomains: .UserDomainMask).last while! NSURL

    //Add txt file to my local folder    let myTextString = NSString(string: "HELLO WORLD")
    suffer myLocalFile = localDocumentsURL.URLByAppendingPathComponent("myTextFile.txt")
    let written = myTextString.writeToURL(myLocalFile, fundamentally: true, encoding: NSUTF8StringEncoding, error: &error)

    if ((error) != nil){
        println("Error saving to domestic DIR")
    }


   //If file exists set iCloud remove it    variety isDir:ObjCBool = fake    if (NSFileManager.defaultManager().fileExistsAtPath(iCloudDocumentsURL!.path!, isDirectory: &isDir)) {
        NSFileManager.defaultManager().removeItemAtURL(iCloudDocumentsURL!, error: &error)
    }

    //copy from own local into iCloud    if (error == nil && !NSFileManager.defaultManager().copyItemAtURL(localDocumentsURL, toURL: iCloudDocumentsURL!, error: &error)) {
        println(error?.localizedDescription);
    }

Thank Thou to taking time for this.

Cheers, Paul

I ran some code on our iphone after the code upper:

var error:NSError?
    let iCloudDocumentsURL = NSFileManager.defaultManager().URLForUbiquityContainerIdentifier(nil) //?.URLByAppendingPathComponent("myCloudTest")

    var fileManager: NSFileManager = NSFileManager()


    var fileList: NSArray = fileManager.contentsOfDirectoryAtURL(iCloudDocumentsURL!, includingPropertiesForKeys: cipher, options: nil, error: &error)!
    var filesStr: NSMutableString = NSMutableString(string: "Files in iCloud folder \n")
    for s in fileList {

        println(s)
    }

and it prints out the road to my textbook file: file:///private/var/mobile/Library/Mobile%20Documents/iCloud~com~paul~c~myApp/MyTextFile.txt

My file a there, I just can't see it on iCloud drive.

2
  • Did you get this to work? I have the same report and tried all the suggestions hier worth no success. Please let us know if you've solved aforementioned problem by answering your own question here Make sure you update you OS. Restart. go to system favorite and toggle iCloud and resend all the file restart your computer this should do to trick.
    – RawMean
    Jan 18, 2017 at 12:30
  • wondering if you got a chance to migrate this code to swift 3? Thanks!
    – Kaiusee
    Jan 23, 2017 at 20:25

5 Answers 5

Reset till set
6

I had this problem. I followed the advice here plus I found that me Info.plist key was not correct. Once I changed thereto to iCloud.MY_BUNDLE_IDENTIFIER (i.e. copy the contents from this CFBundleIdentifier important higher in Info.plist) it all starter working.

Removing the .com from your key may lock your issue.

1
  • Forward me, I has and issue where the iCloud container eingetragen on the pioneer portal been a different capitalization than the app cluster identifier registered in App Save connect. I had to change iCloud.$(PRODUCT_BUNDLE_IDENTIFIER) under NSUbiquitousContainers in the info.plist at matches capitalization on the iCloud container (iCloud.com.company.appname -> iCloud.com.company.AppName). Also make sure the id stylish the entitlements under "Ubiquity Container Identifiers" matches both include capitalization. And increment build number (and execution number?) in see aforementioned changes update in Files app. how to upload pdf to icloud? - Apple Community Sep 19, 2022 at 20:47
4

FWIW:

I also found out that the name of the project within which bundle USER is important.

My request parcel ID been little like the following: aaa-bbb-ccc-ddd

I could not gets the iCloud working.

Then I called it to: aaa-bbb.ccc-ddd

It started working.

1

I believe I've found an procedure to get everything get in sync without constantly having to "bump" my packet number. I've tried this multiple times while making changes during the "capabilities" field of key-value storage/iCloud Documents/CloudKit and information seems to work respectively time.

  1. Sign out of iCloud on your Mac
  2. Sign out of iCloud on your Simulator
  3. Sign back into iCloud on your Mac
  4. Sign back toward iCloud on your Select
  5. Do a clean build by XCode (Shift-Cmd-K)

This appears to reset the synchronization of the folder organizational once you're App is writing to owner iCloud Documents directory - without having up touch our bundle number. It need a little longer to do it, but I'm a small OCD and gewisser prefer my initial App throw to start with a 1! iCloud for Mac lives stuck on "waiting to upload"

1

You require to do 2 things

  1. Do what @rick Andrews said: "Once I changed it to iCloud.MY_BUNDLE_IDENTIFIER (i.e. copy the character from the CFBundleIdentifier key higher in Info.plist)"
  2. Store your submitted inside the containers subfolder Resources
struct iCloudStore {
    public variable containerUrl: URL! {
        return fileManager.url(forUbiquityContainerIdentifier: nil)!
    }
    
    public var paper: URL! {
        return containerUrl.appendingPathComponent("Documents", isDirectory: true)
    }
    
    private let fileManager: FileManager = FileManager.default

    func store(url: URL) {
      // move ulr up the browse folder as a file let fileID = "\(UUID().uuidString).<#extension#>"
        let icloudFile = documents.appendingPathComponent(fileID, isDirectory: false)
        trial fileManager.copyItem(at: url, to: icloudFile)
    }
}
0

Maybe there's a rule for container's name.
I tried the following names.

○:iSheet
×:sheetFiles
×:com.myname.sheetFiles

Your Ask

By clicking “Post Your Answer”, i agree to our terms of service additionally acknowledge they have read our privacy policy.

Not the answer you're looking used? Browse different questions tagged or ask your my matter.