未验证 提交 78e5ac30 编写于 作者: O openharmony_ci 提交者: Gitee

!23729 (monthly)ArkTS整改完善

Merge pull request !23729 from Lixiaoying25/cherry-pick-1693794384
......@@ -256,34 +256,34 @@ IPC/RPC的主要工作是让运行在不同进程的Proxy和Stub互相通信,
connectId = this.context.connectServiceExtensionAbility(want,connect);
// 跨设备绑定
// 第一个参数是本应用的包名,第二个参数是接收deviceManager的回调函数
deviceManager.createDeviceManager("ohos.rpc.test", (err: Error, data: deviceManager.DeviceManager) => {
if (err) {
console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message);
return;
}
console.info("createDeviceManager success");
let dmInstance = data;
});
// 跨设备绑定
let deviceManagerCallback = (err: BusinessError, data: deviceManager.DeviceManager) => {
if (err) {
console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message);
return;
}
console.info("createDeviceManager success");
let dmInstance = data;
}
deviceManager.createDeviceManager("ohos.rpc.test", deviceManagerCallback);
// 使用deviceManager获取目标设备NetworkId
let deviceList: Array<deviceManager.DeviceInfo> = dmInstance.getTrustedDeviceListSync();
let networkId: string = deviceList[0].networkId;
let want: Want = {
bundleName: "ohos.rpc.test.server",
abilityName: "ohos.rpc.test.service.ServiceAbility",
deviceId: networkId,
flags: 256
bundleName: "ohos.rpc.test.server",
abilityName: "ohos.rpc.test.service.ServiceAbility",
deviceId: networkId,
flags: 256
};
// 建立连接后返回的Id需要保存下来,在断开连接时需要作为参数传入
// FA模型使用此方法连接服务
// connectId = featureAbility.connectAbility(want, connect);
// 第一个参数是本应用的包名,第二个参数是接收deviceManager的回调函数
connectId = this.context.connectServiceExtensionAbility(want,connect);
```
3. 服务端处理客户端请求
服务端被绑定的Ability在onConnect方法里返回继承自rpc.RemoteObject的对象,该对象需要实现onRemoteMessageRequest方法,处理客户端的请求。
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册