Cocos Creator Native Adapter
Overview
The Cocos Native Adapter is a dedicated adapter provided by Cloud Development for the Cocos Creator native platform (iOS/Android), enabling developers to seamlessly use all features of Cloud Development in Cocos Creator native projects. With this adapter, you can easily achieve cloud data storage, user authentication, file management, and function calls on mobile terminals.
Supported Platforms
Currently adapted platforms:
-All platforms supported by Cocos Creator
Environmental Requirements
- Node.js >= 22
- Cocos Creator 3.x
- @cloudbase/js-sdk >= 2.25.1
- @cloudbase/adapter-cocos_native >= 1.0.0
Effect Display
For the complete sample project, refer to: CloudBase Cocos Demo




Installation
Install with npm:
npm install @cloudbase/js-sdk @cloudbase/adapter-cocos_native
Quick Start
Adapter configuration
import cloudbase from "@cloudbase/js-sdk";
import adapter from "@cloudbase/adapter-cocos_native";
Register adapter
cloudbase.useAdapters(adapter);
const app = cloudbase.init({
env: "your-env-id", // Replace this value with your environment ID
region: "ap-shanghai", // Region
accessKey: "your-access-key", // Publishable Key
});
export default app;
adapter must be called before cloudbase.init()
Features
- Network request: Implemented using XMLHttpRequest, optimized for compatibility with Cocos Native platform
- Local storage: Uses
cc.sys.localStorage, sessionStorage is unsupported in native environments - AbortController: Built-in polyfill supports request termination, no installation required
Environment test
The adapter automatically detects whether the current value is a Cocos Native environment. Detection criteria include:
ccglobal object existscc.sys.isNativeistrue-XMLHttpRequestandWebSocketare available
Main dependency
| dependency | version | description |
|---|---|---|
| @cloudbase/js-sdk | >=2.25.1 | Tencent Cloud Development SDK |
| @cloudbase/adapter-cocos_native | ^1.0.0 | Cocos Native adapter |
FAQs
Q: Why call useAdapters before init?
A: The adapter needs to be registered before SDK initialization to ensure the SDK can correctly identify the current runtime environment and use the appropriate adapter.
Q: What are the limits of local storage?
A: The Cocos Native environment uses cc.sys.localStorage for local storage and does not support sessionStorage.
Q: Which versions of Cocos Creator are supported?
A: The adapter supports Cocos Creator 3.x version.