10 Replies
      Latest reply on Jun 18, 2018 10:11 AM by JoePasadena
      JoePasadena Level 1 Level 1 (0 points)

        in my app, I saved my data to iPhone FileSystem, but I realized that once I lost the phone the data was gone, so I was thinking about moving the important data to iCloud storge? How can I do that?

        I am using the below URL to acess the local iPhone File System.

         

        static let DocumentsDirectory = FileManager().urls(for: .documentDirectory, in: .userDomainMask).first!

        • Re: How to store and retrieve data from iCloud?
          KMT Level 9 Level 9 (15,785 points)

          You can't use iCloud in that example with Xcode free provisioning.

           

          Pls. reread the free provisioning process I linked in your other thread.

            • Re: How to store and retrieve data from iCloud?
              JoePasadena Level 1 Level 1 (0 points)

              OK. Then a quesiton comes up that if I paid $99 and put an app in app store, after one year, I stopped paying, did app store remove the app then?

                • Re: How to store and retrieve data from iCloud?
                  KMT Level 9 Level 9 (15,785 points)

                  If you don't renew your paid account, yes, all apps associated with that account go dark.

                    • Re: How to store and retrieve data from iCloud?
                      JoePasadena Level 1 Level 1 (0 points)

                      Now I am ready to pay the annual fee, so how can I store and retrieve the data from iCloud?

                      so that when I type my data from my iPhone and I get the same data from iPad.

                      If my iPhone was broken or lost, the data is still there and I can access the same data via my new iPhone X1, X2 etc.

                        • Re: How to store and retrieve data from iCloud?
                          KMT Level 9 Level 9 (15,785 points)

                               >how can I store and retrieve the data from iCloud?

                           

                          Guides and sample code are linked here: https://developer.apple.com/icloud/cloudkit/

                           

                          Good luck.

                            • Re: How to store and retrieve data from iCloud?
                              JoePasadena Level 1 Level 1 (0 points)

                              About the iCloud, is the following method all possible?

                              1. just save the data into Document folder, will iCloud automatically upload the file into iCloud? can a second device access the data?

                              2. still saving the data into one single file via CloudKit.

                              3. using database via CloudKit, is this method more efficient than the file based one above?

                                • Re: How to store and retrieve data from iCloud?
                                  eskimo Apple Staff Apple Staff (13,905 points)

                                  1. just save the data into Document folder, will iCloud automatically upload the file into iCloud?

                                  No.

                                  2. still saving the data into one single file via CloudKit.

                                  I don’t understand this question.

                                  3. using database via CloudKit, is this method more efficient than the file based one above?

                                  I don’t think this question makes sense given my answer to question 1.


                                  iCloud is a marketing term that encompasses many different technologies:

                                  • iCloud documents

                                  • iCloud user defaults

                                  • CloudKit

                                  • iCloud Backup

                                  • iCloud Photo Library

                                  • iCloud Keychain

                                  • iCloud email (IMAP plus some extensions)

                                  • iCloud contacts (CardDAV plus some extension, also accessible via the Contacts framework)

                                  • iCloud calendar (CalDAV plus some extension, also accessible via the EventKit framework)

                                  • and so on

                                  Which of these is the best for your specific application depends on the needs of your application.  For example:

                                  • If you have a classic, document-based application, iCloud documents is a great option.  In terms of APIs you should look to UIDocument and UIDocumentBrowserViewController.

                                  • If you have a ‘shoebox’ application, where you’re just showing the user a view of some underlying database, CloudKit is great.

                                  • If you want to save a few, small preferences, that’s perfect for iCloud user defaults.

                                  • If you want to save user secrets, take a look at iCloud Keychain.

                                  • If you only care about the lost phone, you may just need to put your file in a place where it’s covered by the backup system (either iCloud Backup or iTunes backup).

                                  If the above doesn’t cover your situation, please post more details about what your app is doing with this data.

                                  Share and Enjoy

                                  Quinn “The Eskimo!”
                                  Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                                  let myEmail = "eskimo" + "1" + "@apple.com"

                                  WWDC runs Mon, 4 Jun through to Fri, 8 Jun.  During that time all of DTS will be at the conference, helping folks out face-to-face.

                                    • Re: How to store and retrieve data from iCloud?
                                      JoePasadena Level 1 Level 1 (0 points)

                                      My app has some private user data, just like any other apps. The data is user defined,  including numbers and photo, user can add or modify it.

                                      so my question became.

                                      #1, if I save my app's private data (files) into iCould Document directory, will iCloud sync it automatically without my app itself to worry about it. My app just write to these files, that's it.

                                       

                                      #2. If I have to use iCloud Kit, because my app is very simple, it has only two files, so can I use file based via iCloud Kit instead of dealing with Database(private, public, shared) record etc mentioned in iCloud Kit?

                                       

                                      #3. What's the benifit using Database over File, let's say iCloud Photo Library, has it used the database concept to maintain the photos or just maintianing these photo files itself? What's the advantage using the Database/record concept?

                                        • Re: How to store and retrieve data from iCloud?
                                          eskimo Apple Staff Apple Staff (13,905 points)

                                          #1, if I save my app's private data (files) into iCould Document directory, will iCloud sync it automatically without my app itself to worry about it.

                                          Syncing is hard in general, so there’s no solution where you can just not “worry about it”.  If you use the iCloud document architecture then the system takes care of moving all the bits and bobs around but you still have to worry about resolving conflicts.  The Conflict Resolution and Error Handling section of the UIDocument documentation discusses this.

                                          #2. If I have to use iCloud Kit, because my app is very simple, it has only two files, so can I use file based via iCloud Kit instead of dealing with Database(private, public, shared) record etc mentioned in iCloud Kit?

                                          No.  CloudKit works primarily in terms of database records; it can manipulate files but that’s not the best way to approach this.

                                          #3. What's the benifit using Database over File, let's say iCloud Photo Library, has it used the database concept to maintain the photos or just maintianing these photo files itself?

                                          There are lots of trade-offs here, including:

                                          • Using files makes sense if you have a document architecture.  Consider an app like Pages: it lets the user open and close specific documents, share documents, and so on.  This is a good fit for UIDocument.

                                          • A database lets you work with larger data structures.  For example, iTunes uses a database internally because the user might have tens of thousands of songs, and managing all of that info in a ‘flat’ file is not going to perform well.

                                          • A database can also help with syncing, because it lets you sync records rather than entire files.

                                          Share and Enjoy

                                          Quinn “The Eskimo!”
                                          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                                          let myEmail = "eskimo" + "1" + "@apple.com"