share(params: Object)

Requires:
BizKit≥3.0.0@ray-js/ray≥0.3.23
Platforms:
iOS
import { share } from '@ray-js/ray';

// Promise usage
try {
  const res = await share({ ...params });
  console.log(res);
} catch (err) {
  console.log(err.errorMsg);
}

Description

Share text, images, files, web pages, or mini program content via the specified channel

Parameters

PropertyTypeRequiredDefaultDescription
type"WeChat" | "Message" | "Email" | "More"No'WeChat'Share channel; defaults to WeChat if omitted. Options: WeChat, Message, Email, More
titlestringYes-title Title
messagestringYes-message Text content
contentType"text" | "image" | "file" | "web" | "miniProgram"No'text'contentType Content type
recipientsstring[]No-recipients Email/SMS recipients
imagePathstringNo-imagePath Image path
filePathstringNo-File share path, used when contentType == file; omitting it will cause the file share to fail
webPageUrlstringNo-web Used when contentType == file
No-miniProgramInfo Used when contentType == miniProgram, and the share channel must be WeChat.
complete() => voidNo-Completion callback (executed on both success and failure)
success() => voidNo-Callback on successful API call
fail(params: Object) => voidNo-Failure callback
fail callback parameters
PropertyTypeDescription
errorMsgstringError message
errorCodestring | numberError code
Error extension

Return Value

None

Valid Values

type
ValueDescriptionBizKit Since
WeChatWeChatv4.14.8
MessageSMSv4.14.8
EmailEmailv4.14.8
MoreMore system share options (invoke system share)v4.14.8
contentType
ValueDescriptionBizKit Since
textTextv4.14.8
imageImagev4.14.8
fileFilev4.14.8
webWeb page URLv4.14.8
miniProgramWeChat Mini Program share contentv4.14.8

Examples

import { share } from '@ray-js/ray'

share({
  type: "WeChat",
  title: "xx",
  message: "xx",
  contentType: "text",
  recipients: [],
  imagePath: "xx",
  filePath: "xx",
  webPageUrl: "xx",
  miniProgramInfo: {},
  success: data => {
    console.log(data);
  },
  fail: error => {
    console.error(error);
  },
});