A keychain can be used to persistently store specific data, but this is not particularly secure. While the keychain will not be affected by the iOS update, it will be reset after the system is restored. In addition, the information stored on the key string of the device cannot be read if the device is damaged and cannot be used.

For some specific needs, we may need to use iCloud to store specific data. Let’s not talk about the principle, but let’s get started.

1. Add the iCloud container

Go to the Apple Developer Center and add iCloud Containers, also known as iCloud Containers, as shown here

The bundle ID format is iCloud.+ Bundle ID. This bundle ID does not have to be the bundle ID of your project, as long as you add the container to your APP ID.

2. Configuration “Capabilities

Turn on the iCloud feature in the project, add the container to it, and it may be automatically configured for you as well

3.

With the NSURL * url = [manager URLForUbiquityContainerIdentifier: nil]; To check whether iCloud is enabled. If the URL is empty, iCloud is not enabled

Use 4.

1. Check whether the iCloud stores required data

2. Add data to iCloud

3. This is the core method, and everything above calls this private method

5. The appendix

Done, as long as follow my steps, there will be no problem ~~


The authors introduce

  • Wei Yuxiang: iOS development engineer of Guangzhou Reed APP Team

Push the information

  • We are recruiting partners, interested partners can send your resume to [email protected], note: from the nuggets community
  • For details, please click here –> Guangzhou Reed Information Technology