枭云
枭云
  • 发布:2024-12-06 12:06
  • 更新:2024-12-06 14:55
  • 阅读:125

开发鸿蒙应用使用uts插件调用分享服务报错

分类:HBuilderX

项目中含有将pdf文件分享到其他应用打开的需求,参照鸿蒙文档的调用示例,真机运行时报错

编辑器版本:4.36

鸿蒙文档链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V13/share-utd-text-V13

报错信息:
496 WARN: ArkTS:WARN File: E:/hongmeng/jianlizhizuo/resume_hm/unpackage/debug/app-harmony-26d8f534/oh_modules/.ohpm/@dcloudio+uni-app-runtime@onjt5cnkmpxv8bm+y1oo6mnpqjw8oa6bpkmtp8h3hxs=/oh_modules/@dcloudio/uni-app-runtime/src/main/ets/uni-app-harmony/uni.api.ets:7609:13
The system capacity of this api 'scanCore' is not supported on all devices

1 ERROR: ArkTS:ERROR File: E:/hongmeng/jianlizhizuo/resume_hm/unpackage/debug/app-harmony-26d8f534/uni_modules/share-1/utssdk/app-harmony/index.ets:7:72
Argument of type 'UTSJSONObject' is not assignable to parameter of type 'SharedRecord'.
Property 'utd' is missing in type 'UTSJSONObject' but required in type 'SharedRecord'.

2 ERROR: ArkTS:ERROR File: E:/hongmeng/jianlizhizuo/resume_hm/unpackage/debug/app-harmony-26d8f534/uni_modules/share-1/utssdk/app-harmony/index.ets:7:72
Conversion of type '{ utd: utd.UniformDataType; content: string; title: string; description: string; }' to type 'UTSJSONObject' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
Type '{ utd: UniformDataType; content: string; title: string; description: string; }' is missing the following properties from type 'UTSJSONObject': _resolveKeyPath, _getValue, get, set, and 8 more.

3 ERROR: ArkTS:ERROR File: E:/hongmeng/jianlizhizuo/resume_hm/unpackage/debug/app-harmony-26d8f534/uni_modules/share-1/utssdk/app-harmony/index.ets:15:30
Conversion of type '{ selectionMode: systemShare.SelectionMode; previewMode: systemShare.SharePreviewMode; }' to type 'UTSJSONObject' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
Type '{ selectionMode: SelectionMode; previewMode: SharePreviewMode; }' is missing the following properties from type 'UTSJSONObject': _resolveKeyPath, _getValue, get, set, and 8 more.

4 ERROR: ArkTS:ERROR File: E:/hongmeng/jianlizhizuo/resume_hm/unpackage/debug/app-harmony-26d8f534/uni_modules/share-1/utssdk/app-harmony/index.ets:15:30
Type 'UTSJSONObject' has no properties in common with type 'ShareControllerOptions'.

COMPILE RESULT:FAIL {ERROR:5 WARN:517}

hvigor ERROR: BUILD FAILED in 10 s 413 ms
11:57:00.770 运行包制作失败

2024-12-06 12:06 负责人:无 分享
已邀请:

最佳回复

DCloud_UNI_yuhe

DCloud_UNI_yuhe

在使用 uts 插件开发鸿蒙插件时,如果报错类似于:Type 'UTSJSONObject' has no properties in common with type 'ShareControllerOptions'. 关于 UTSJSONObject 类似的错误,是在转 arkts 时,将类型转为 UTSJSONObject 时出错。

下面举例:

let shareData : systemShare.SharedData = new systemShare.SharedData({  
    utd: utd.UniformDataType.TEXT,  
    content: '这是一段文本内容',  
    title: '文本内容', // 不传title字段时,显示content  
    description: '文本描述',  
    // thumbnail: new Uint8Array() // 推荐传入适合的缩略图 不传则显示默认text图标  
} );

这个代码在编译时会报错,需要指定类型

let shareData : systemShare.SharedData = new systemShare.SharedData({  
    utd: utd.UniformDataType.TEXT,  
    content: '这是一段文本内容',  
    title: '文本内容', // 不传title字段时,显示content  
    description: '文本描述',  
    // thumbnail: new Uint8Array() // 推荐传入适合的缩略图 不传则显示默认text图标  
}  as systemShare.SharedRecord);
  • 枭云 (作者)

    多谢,问题已解决

    2024-12-06 14:59

要回复问题请先登录注册