native.js 522 B

12345678910111213141516171819202122232425
  1. export default function ({ $userAgent }, i) {
  2. const before = () => {
  3. if ($userAgent.isApp) {
  4. return;
  5. }
  6. throw new Error('非App环境');
  7. };
  8. i('native', {
  9. share({ title, content, gotoUrl, shareImg }) {
  10. before();
  11. if ($userAgent.isIos) {
  12. window.webkit.messageHandlers.share.postMessage({
  13. title,
  14. content,
  15. gotoUrl,
  16. shareImg,
  17. });
  18. } else {
  19. window.native.share(title, content, gotoUrl, shareImg);
  20. }
  21. },
  22. });
  23. }