1e41f4b71Sopenharmony_ci# MissionCallback (系统接口) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci作为可以[registerMissionListener](js-apis-distributedMissionManager-sys.md#distributedmissionmanagerregistermissionlistener)的入参,表示开始同步后,建立的回调函数。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **说明:** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8e41f4b71Sopenharmony_ci> 本模块接口为系统接口。 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## 导入模块 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci```ts 13e41f4b71Sopenharmony_ciimport { distributedMissionManager } from '@kit.AbilityKit'; 14e41f4b71Sopenharmony_ci``` 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci## MissionCallback.notifyMissionsChanged 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Mission 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci**系统接口**:该接口为系统接口。 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci**参数:** 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 25e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 26e41f4b71Sopenharmony_ci| deviceId | string | 是 | 通知任务变化,返回设备ID。| 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci**示例:** 29e41f4b71Sopenharmony_ci```ts 30e41f4b71Sopenharmony_ciimport { distributedMissionManager } from '@kit.AbilityKit'; 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_cidistributedMissionManager.registerMissionListener( 33e41f4b71Sopenharmony_ci { 34e41f4b71Sopenharmony_ci deviceId: '123456' 35e41f4b71Sopenharmony_ci }, 36e41f4b71Sopenharmony_ci { 37e41f4b71Sopenharmony_ci notifyMissionsChanged: (deviceId: string) => { 38e41f4b71Sopenharmony_ci console.log(`notifyMissionsChanged deviceId: ${JSON.stringify(deviceId)}`); 39e41f4b71Sopenharmony_ci }, 40e41f4b71Sopenharmony_ci notifySnapshot: (deviceId: string, mission: number) => { 41e41f4b71Sopenharmony_ci console.log(`notifySnapshot deviceId: ${JSON.stringify(deviceId)}`); 42e41f4b71Sopenharmony_ci console.log(`notifySnapshot mission: ${JSON.stringify(mission)}`); 43e41f4b71Sopenharmony_ci }, 44e41f4b71Sopenharmony_ci notifyNetDisconnect: (deviceId: string, state: number) => { 45e41f4b71Sopenharmony_ci console.log(`notifyNetDisconnect deviceId: ${JSON.stringify(deviceId)}`); 46e41f4b71Sopenharmony_ci console.log(`notifyNetDisconnect state: ${JSON.stringify(state)}`); 47e41f4b71Sopenharmony_ci } 48e41f4b71Sopenharmony_ci } 49e41f4b71Sopenharmony_ci); 50e41f4b71Sopenharmony_ci``` 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci## MissionCallback.notifySnapshot 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Mission 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci**系统接口**:该接口为系统接口。 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci**参数:** 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 61e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 62e41f4b71Sopenharmony_ci| deviceId | string | 是 | 通知快照变化,返回设备ID。 | 63e41f4b71Sopenharmony_ci| mission | number | 是 | 通知快照变化,任务ID。 | 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci**示例:** 66e41f4b71Sopenharmony_ci```ts 67e41f4b71Sopenharmony_ciimport { distributedMissionManager } from '@kit.AbilityKit'; 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_cidistributedMissionManager.registerMissionListener( 70e41f4b71Sopenharmony_ci { 71e41f4b71Sopenharmony_ci deviceId: '123456' 72e41f4b71Sopenharmony_ci }, 73e41f4b71Sopenharmony_ci { 74e41f4b71Sopenharmony_ci notifyMissionsChanged: (deviceId: string) => { 75e41f4b71Sopenharmony_ci console.log(`notifyMissionsChanged deviceId: ${JSON.stringify(deviceId)}`); 76e41f4b71Sopenharmony_ci }, 77e41f4b71Sopenharmony_ci notifySnapshot: (deviceId: string, mission: number) => { 78e41f4b71Sopenharmony_ci console.log(`notifySnapshot deviceId: ${JSON.stringify(deviceId)}`); 79e41f4b71Sopenharmony_ci console.log(`notifySnapshot mission: ${JSON.stringify(mission)}`); 80e41f4b71Sopenharmony_ci }, 81e41f4b71Sopenharmony_ci notifyNetDisconnect: (deviceId: string, state: number) => { 82e41f4b71Sopenharmony_ci console.log(`notifyNetDisconnect deviceId: ${JSON.stringify(deviceId)}`); 83e41f4b71Sopenharmony_ci console.log(`notifyNetDisconnect state: ${JSON.stringify(state)}`); 84e41f4b71Sopenharmony_ci } 85e41f4b71Sopenharmony_ci } 86e41f4b71Sopenharmony_ci); 87e41f4b71Sopenharmony_ci``` 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci## MissionCallback.notifyNetDisconnect 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Mission 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci**系统接口**:该接口为系统接口。 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci**参数:** 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 98e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 99e41f4b71Sopenharmony_ci| deviceId | string | 是 | 通知断开连接,返回设备ID。 | 100e41f4b71Sopenharmony_ci| state | number | 是 | 通知断开连接,网络状态。 | 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci**示例:** 103e41f4b71Sopenharmony_ci```ts 104e41f4b71Sopenharmony_ciimport { distributedMissionManager } from '@kit.AbilityKit'; 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_cidistributedMissionManager.registerMissionListener( 107e41f4b71Sopenharmony_ci { 108e41f4b71Sopenharmony_ci deviceId: '123456' 109e41f4b71Sopenharmony_ci }, 110e41f4b71Sopenharmony_ci { 111e41f4b71Sopenharmony_ci notifyMissionsChanged: (deviceId: string) => { 112e41f4b71Sopenharmony_ci console.log(`notifyMissionsChanged deviceId: ${JSON.stringify(deviceId)}`); 113e41f4b71Sopenharmony_ci }, 114e41f4b71Sopenharmony_ci notifySnapshot: (deviceId: string, mission: number) => { 115e41f4b71Sopenharmony_ci console.log(`notifySnapshot deviceId: ${JSON.stringify(deviceId)}`); 116e41f4b71Sopenharmony_ci console.log(`notifySnapshot mission: ${JSON.stringify(mission)}`); 117e41f4b71Sopenharmony_ci }, 118e41f4b71Sopenharmony_ci notifyNetDisconnect: (deviceId: string, state: number) => { 119e41f4b71Sopenharmony_ci console.log(`notifyNetDisconnect deviceId: ${JSON.stringify(deviceId)}`); 120e41f4b71Sopenharmony_ci console.log(`notifyNetDisconnect state: ${JSON.stringify(state)}`); 121e41f4b71Sopenharmony_ci } 122e41f4b71Sopenharmony_ci } 123e41f4b71Sopenharmony_ci); 124e41f4b71Sopenharmony_ci``` 125