Cocos (JavaScript) - Auth
Interacting with Particle Auth within applications made using Cocos.
Particle Auth for Cocos
Particle Auth supports Cocos through the Particle Auth Cocos SDK, enabling full integration of Particle’s Wallet-as-a-Service within Cocos-based game applications.
The usage of Particle Auth with Cocos is nearly identical to React Native (JavaScript), with the main differences being in prerequisites and initial setup.
This document will guide you through the setup process. For usage examples, refer to the React Native (JavaScript) documentation.
Getting Started
To start the setup process for the Particle Auth Cocos SDK, make sure your project meets the following prerequisites to ensure compatibility:
- Cocos 3.7.2 or higher.
- For iOS:
- Xcode 15.0 or higher.
- CocoaPods 1.14.3 or higher.
- iOS 14 or higher.
- For Android:
- Minimum API Level 23 or higher.
- Targets API Level 31 or higher.
- Java SDK version 11.
Next, you’ll need to retrieve three essential values from the Particle dashboard, which are required across all of Particle’s SDKs: projectId
, clientKey
, and appId
.
Follow the quickstart tutorial to set up a project and find the required keys: Create a new project.
Installation and configuration
To install and start using the Particle Auth Cocos SDK in your project, follow these steps:
Step 1: Copy the Core Assets
-
Locate the Core Assets directory:
- Navigate to the assets/Mobile/Core directory in the
particle-cocos
repository.
- Navigate to the assets/Mobile/Core directory in the
-
Copy the Core Assets directory:
- Copy the entire
Core
folder to your project’sassets
directory.
- Copy the entire
Step 2: Copy the Native Engine Files
-
Locate the Native Engine directory:
- Navigate to the native/engine directory in the
particle-cocos
repository.
- Navigate to the native/engine directory in the
-
Copy the Native Engine directory:
- Copy the entire
engine
directory to your project’snative
directory.
- Copy the entire
Android
If you’re using Cocos on Android, the configuration is quite simple and purely requires the placement of the previously retrieved values (projectId
, clientKey
, and appId
) within $exportDir/proj/gradle.properties,
such as within the example below.
iOS
If you use iOS, the initial configuration will be more complicated. To begin, ensure you have a Podfile.
If you don’t have one already, head over to the root of your Xcode project directory and run:
Head into this newly generated (or existing) Podfile and remove all existing contents, then paste the configuration included below.
Alternatively, if you’re already using other SDKs through CocoaPods, you can include the Particle Auth SDK declaration:
Additionally, you can run pod install --repo-update
, then open {your project}.xcworkspace
to update and see your project within Xcode.
Now that you’ve configured your Particle dashboard, installed the SDK, and configured a Podfile, it’s time to initialize the SDK with the aforementioned projectId
, clientKey
, and appId
retrieved from the Particle dashboard.
-
Create a
ParticleNetwork-Info.plist
file from the root of your corresponding Xcode project. -
Paste the following text into this file:
ParticleNetwork-Info.plist -
Replace the placeholders with the values retrieved from your project and application within the Particle dashboard.
-
Drop the following files into your project and set the target at the main app. Make sure
Base58.swift
,Model.swift
, andParticleAuthPlugin.swift
are marked withinTargetMembership
.If Xcode asks to make a Swift bridging file, select Yes.
- Open your
AppDelegate
file and include a custom return within the(BOOL)application:openURL:options:
method, as shown in the example below:
- Within
AppDelegate
, ensure a project-specific import is included at the top of the file. This should be#import "{project name}-Swift.h"
.
JsbBridgeTest.m
and JsbBridgeTest.h
are crucial components, serving as the core bridge between JS and native code.
To prevent any issues arising from improper setup, ensure that the code within these files matches the code from the demo or includes the exact code from it.
- Finally, to configure your app scheme URL, select your app from “TARGETS” within the “Info” section, click the plus icon to add the URL types, and paste your scheme in “URL Schemes.”
Defining a scheme URL
Your scheme URL should be “pn” concatenated with your projectId
.
For example, if your project app id is
63bfa427-cf5f-4742-9ff1-e8f5a1b9828f
, your scheme URL is
pn63bfa427-cf5f-4742-9ff1-e8f5a1b9828f
.
Usage
Using the Particle Auth Cocos SDK is identical to the examples provided in the React Native (JavaScript) documentation.
The only difference is the import statement, which should include the internal path ../../Core/particleAuth
, as shown below:
Was this page helpful?