在iOS 14及以下使用navigator share时出现“Type error”错误。

huangapple go评论71阅读模式
英文:

Getting 'Type error' when using navigator share on iOS 14 and below

问题

以下是翻译好的部分:

我想通过点击按钮在Instagram或其他社交媒体上分享一张图片。在Android和iOS 16上,借助navigator.share的帮助,我的代码目前可以正常工作,但在iOS 14或更低版本上,它会不断返回TypeError,没有其他具体信息,并且不允许我分享。
我目前正在使用Angular 12。

获取分享数据的我的代码:

private async getShareData() {
    if (!this._blob) {
        this._blob = await (await fetch(this._shareImgSrc)).blob();
    }
    const file = new File([this._blob], 'image.png', { type: this._blob.type });

    return {
        files: [file],
    };
}

点击分享时执行分享的我的代码:

public async onShare() {
    if (this._isLoading) {
        return;
    }

    this._isLoading = true;
    try {
        const data = await this.getShareData() as ShareData;
        await navigator.share(data)
    } catch (error) {
        alert(`error: ${error.message}`);
    }
    this._isLoading = false;
}
英文:

I want to share an image on Instagram or other social media with a button click. With the help of navigator share, so far my code worked in Android and iOS 16, but with iOS 14 or below it keeps returning TypeError without anything else specific and not allow me to share.
Currently I'm using Angular 12.

My code to get share data:

private async getShareData() {
    if (!this._blob) {
      this._blob = await (await fetch(this._shareImgSrc)).blob();
    }
    const file = new File([this._blob], 'image.png', { type: this._blob.type });

    return {
      files: ,
    };
  }

My code to share when click:

public async onShare() {
    if (this._isLoading) {
      return;
    }

    this._isLoading = true;
    try {
      const data = await this.getShareData() as ShareData;
      await navigator.share(data)
    } catch (error) {
      alert(`error: ${error.message}`);
    }
    this._isLoading = false;
  }

答案1

得分: 1

Navigator Share 在 iOS 14 上不支持。

英文:

Navigator Share is not support on ios 14

huangapple
  • 本文由 发表于 2023年6月6日 17:21:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76413174.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定