英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论