Hi 👋

  • 📚 Personal site: lab.lawliet
  • 📦 Technical documentation
  • 🐙 making
  • WX: RyukieW

My apps

Mine Elic endless sky ladder Dream of books
type The game financial
download AppStore-Elic AppStore-Umemi

Welcome to catch bugs and hook up

One, foreword

This MD document was created in January and has not been filled in.

Although my application itself is not a successful application, but I feel in the process of doing a lot of harvest.

This article will not go into detail about how to use specific classes, or how to write code. These official documents are clearer than anyone else.

The goal is to provide an idea for individual developers.

Most individual developers, like myself, have limited resources, time and energy, but lots of ideas. ICloud is the best tool I’ve come across to build a user system and extend the functional requirements.

I’ve already made two independent apps, both based on iCloud. I welcome feedback, and a five-star review would be the most encouraging

Hey, it’s not a good look to have a UI without a designer

The following will be my mine as an example to do a chat

Ii. Selection of technical scheme for individual project user system

2.1 Self-development

It’s not unheard of, but it’s not something I’m good at. And there are too many issues to consider, including technology, operation and maintenance, and security.

Of course, if there is a big guy who can do all this, this is the best plan.

2.2 LeanCloud

I wrote a Demo for this service in the early stage, so I also considered its service in the selection. After all, there is no obstacle to expand to different platforms in the later stage.

But charge limit is much, specific can go to see by oneself. Pass

2.3 GameCenter

A long time ago there was a study, as the name of the Apple system inside a set of game user system.

It includes comparison basics like users, leaderboards, achievement points, etc.

Although many games have access, but the presence is not high.

From what I know of the GameCenter, it’s hard to expand your feature business by just relying on the center, and you still need another set of things to support it.

So it passed.

Up to 2.4

Your initial understanding of iCloud may be based on the ability to back up and sync photo files.

Here the user system depends on CloudKit, it is recommended to directly read the official documents, you want to know.

Official document: CloudKit

3. What is CloudKit

Store structured app and user data in iCloud containers that all users of your app can share.

The CloudKit framework provides interfaces for moving data between your app and your iCloud containers. You use CloudKit To store your app’s existing data in the cloud so that the user can access it on multiple devices. You can also store it data in a public area where all users can access it.

You can also store data in a public area where all users can access it. You can also store data in a public area where all users can access it.

Data sharing is the core of building a user system.

Determine If CloudKit Is Right for Your App.

4. CloudKit stores data

CloudKit control panel

Enter the DataBase and explain the core components:

4.1 Basic data unit: CKRecord

All data is hosted by CKRecord and stored in a container.

It’s important to note that the iCloud and iCloudDrive services are enabled.

The supported data types are as follows, as stated in the official comment:

/// Acceptable value object classes are:
/// - `String`
/// - `Date`
/// - `Data`
/// - `Bool`
/// - `Int`
/// - `UInt`
/// - `Float`
/// - `Double`
/// - `[U]Int8 et al`
/// - `CKReference / CKRecord.Reference`
/// - `CKAsset`
/// - `CLLocation`
/// - `NSData`
/// - `NSDate`
/// - `NSNumber`
/// - `NSString`
/// - `Array` and/or `NSArray` containing objects of any of the types above
///
/// Any other classes will result in an exception with name `NSInvalidArgumentException`.
///
/// Field keys starting with `_` are reserved. Attempting to set a key prefixed with a `_` will result in an error.
///
/// Key names roughly match C variable name restrictions. They must begin with an ASCII letter and can contain ASCII letters and numbers and the underscore character.
/// The maximum key length is 255 characters.
Copy the code

CKRecord itself contains some basic fields such as creator ID, creation time, modification time, record ID and so on.

Of course, we can also customize the fields so that they are read and written like dictionaries. Specific can be clicked into CKRecord file view, here is no longer said.

4.2 Data Storage Space: Zone

Here are three databases with different access permissions, accessed through CKContainer.

a.Public

  • By default, it can be read by all users and modified by the owner
  • Permissions can be set, which can only be adjusted in the background, not through the API
  • Developers can view it in the background
  • Does not take up the owner’s iCloud storage space
  • Takes up the App’s iCloud storage space

Minesweeper uses this database because it contains leaderboards and needs to be accessible to all users.

Here’s the official two-paragraph explanation:

* Records in a public database * - By default are world readable, owner writable. * - Can be locked down by Roles, a process done in the Developer Portal, a web interface. Roles are not present in the client API. * - Are visible to the application developer via the Developer  Portal. * - Do not contribute to the owner's iCloud account storage quota.Copy the code

This database is available regardless of whether the user’s device has an iCloud account. The contents of the public database are readable by all users of the app, and users have write access to the records, and other objects, The public database’s contents are visible in The developer portal, where you can assign roles to users and restrict access as necessary.

Data in the public database counts toward your app’s iCloud storage quota.

b.Private

  • By default, only the owner can read and write
  • Developers can’t access it behind the scenes
  • Takes up the owner’s iCloud storage space

This is suitable for some privacy strong applications, such as password management applications.

 *  Records in a private database
 *  - By default are only owner readable and owner writable.
 *  - Are not visible to the application developer via the Developer Portal.
 *  - Are counted towards the owner's iCloud account storage quota.
Copy the code

c.Shared

  • Visible only to collaborators authorized through CKShare
  • Developers can’t access it behind the scenes
  • Take up the organizer’s iCloud storage space

I haven’t used this, so I’m not going to go into it.

* Records in a shared database * - Are available to share participants based on the permissions of the enclosing CKShare  * - Are not visible to the application developer via the Developer Portal. * - Are counted towards the originating owner's iCloud account storage quota.Copy the code

4.3 Data table structure: RecordTypes

User is a table that exists by default and does not need to be created. If a user has installed your application, CloudKit will automatically generate a record in the background when you retrieve the user object. Isn’t it convenient?

I created these tables based on the requirements scenario for minesweeper Elic

  • The User (the default) : the User
  • Head is AvatarSpace:
  • EndLessRank: Endless game leaderboard
  • GameHistory: GameHistory
  • AppConfig: application configuration
  • ZenRank: Zen mode leaderboard

Add custom fields

Click on the corresponding Type to see the table structure. The top half is the default data structure. Click + below to add a custom field and select a data type.

Note that in the test environment, new fields can be removed. Once it’s online, it can’t be removed. Only new.

4.4 Data index: Indexs

  • QUERYABLE
    • Can query
  • SORTABLE
    • Can be sorted
  • SEARCHABLE
    • searchable

Set this parameter as required. Otherwise, data cannot be read.

  • Endless leaderboards, for example, need to be sorted by time and ranklevel & durationSet upSORTABLE

Effect:

Five, the QA

5.1 Is iCloud Secure?

Although there is no absolute security, but compared to the market cloud storage services. Apple’s is relatively reassuring.

The key is cheap!

5.2 What if the user captures packets and changes data?

I tried to grab the bag, and it just couldn’t connect to the container. Those who are interested can try it.

5.3 crack?

At this point, I pulled out my jailbreak… Let’s do it. Get one out and redo it.

Want to understand the shell please move: application shell

Oh, boy, it just went down. It’s safe now, isn’t it?

Of course, I didn’t go into the details of whether or not we can skip the verification of the system, until Sal has a better idea.

I haven’t made anti-hook yet. If you are interested in cracking it, please contact me. Welcome.

5.4 Access Speed

Not very fast, but enough. The main thing is to design the table structure properly. If you include resource files directly in the data structure of the list, the request speed and user experience will be terrible.

5.5 O&M Costs

It’s hardly operational. There’s nothing we can do. The best you can do as a developer is to design the application logic and data structure to make sense.

Some basic operation data is also visible in the background.

5.6 cross-platform

It’s ok to just do iOS, but if you want to expand to different platforms in the future, you won’t be able to use it. Do you want to do a separate set, or even migrate users?

Rest assured, Apple has thoughtfully provided APICloudKit JS

No specific research, it seems to be possible to do cross-platform.

5.7 capacity

Is 1PB enough?

I’m sorry. I didn’t catch this unit the first time I saw it.

It’s 1024 terabytes. I don’t know.

You don’t get 1P all at once, it comes with the magnitude of your users.

All developers need to care about is the size of the Public Database.

Build Apps Using CloudKit

5.8 Resource Storage CKAsset

CloudKit provides the data type CKAsset to save some resource files, which can be stored in CKRecord.

It looks convenient.

The problem

For example, the minesweeper leaderboard function needs to display the avatar.

In this case, if you add the avatar directly to the User table, it will be very slow to actually pull the User, because you will bring the image resources down with you. Not in the form of a Url that we normally do.

It is also ok to add the image Url field if you upload the image to the graph bed, but in recent years I feel that the graph bed has become more and more restricted, and it is not convenient to use.

Here I have a separate key table to save the image resources, and then encapsulate a load, cache CKAsset image resources tool, easy to use in the ranking version.

Seven,

ICloud is a great thing for individual developers to build a user base at a low cost.

There are a lot of things you can do with your imagination.

I’m only using part of CloudKit here, but there’s a lot I haven’t used yet. There may still be plenty of room for discovery.

Eight, reference

  • CloudKit
  • Designing apps using CloudKit.
  • Build Apps Using CloudKit
  • CloudKit JS
  • Determine If CloudKit Is Right for Your App