Initialize mPaaS
Prerequisites
After running mppm init, mppm installs the framework component by default. Check the oh-package.json5 file in the entry directory for the @mpaas/framework dependency. If it is missing, run mppm init again. For more information, see Initialize the project.
Download the configuration file
In the mPaaS AppCenter console, download the configuration file for HarmonyOS NEXT. Rename the file to mpaas.config and move it to the rawfile directory of your entry project.
Initialization and usage
Manually create a new ArkTs file named EntryAbilityStage. For more information, see the official HarmonyOS documentation, AbilityStage Component Container.
Initialize the framework in the onCreate callback of AbilityStage.
import AbilityStage from '@ohos.app.ability.AbilityStage';
import { MPFramework } from '@mpaas/framework';
export default class EntryAbilityStage extends AbilityStage {
async onCreate() {
const app = this.context;
MPFramework.create(app);
const instance: MPFramework = MPFramework.instance;
const ctx: Context = instance.context
// Initialize other components
}
}Make sure to register this AbilityStage in the module.json5 file.
{
"module": {
"name": "entry",
"type": "entry",
"description": "$string:module_desc",
"mainElement": "EntryAbility",
"srcEntry": "./ets/EntryAbilityStage.ets",
}
}The value of srcEntry depends on the actual file path.
Related APIs
Get udid:
MPFramework.instance.udidImportantThis is an asynchronous API. Add
awaitwhen you call it.Set/Get userId:
MPFramework.instance.userIdSet/Get appSecret:
MPFramework.instance.appSecret