gpt4 book ai didi

android - react-native-fbsdk - 在 android 上分享照片错误

转载 作者:行者123 更新时间:2023-11-29 01:04:36 33 4
gpt4 key购买 nike

当我尝试通过 Facebook ShareDialog 共享照片时,我收到此错误:

Facebook share fail with error: Error: Unsupported scheme for media Uri : data

为了将图像转换为 blob,我使用 react-native-fetch-blobFacebook 分享在 iOS 上运行良好。我什至尝试使用在 iOS 设备上生成的数据对 dataUri 进行硬编码。

版本:

"react": "16.0.0-alpha.12",
"react-native": "0.48.0",
"react-native-fbsdk": "0.6.3",
"react-native-fetch-blob": "^0.10.8",

代码 fragment 。

转换为dataurl:

toDataURL(url) {
return new Promise((resolve, reject) => {
RNFetchBlob.fetch('GET', url)
.then((res) => {
let base64Str = res.base64();
base64Str = 'data:image/jpg;charset=utf-8;base64,' + base64Str;
resolve(base64Str);
})
.catch((errorMessage, statusCode) => {
reject(errorMessage);
})
});
}

分享:

if (attachments.length) {
let attachmentsPromises = attachments.map(a => {
return this.toDataURL(a.url);
});

Promise.all(attachmentsPromises).then(res => {
let shareContent = {
contentType: "photo",
contentUrl: "http://www.google.com",
contentDescription: text,
quote: text,
photos: res.map(dataUrl => {
return {
caption: text,
imageUrl: dataUrl,
userGenerated: true
};
})
};

shareWithFacebook(shareContent);
});
} else {
let shareContent = {
contentType: "link",
contentUrl: "http://www.google.com",
quote: text
};
shareWithFacebook(shareContent);
}

function shareWithFacebook(shareContent) {
console.log('sharing on facebook', shareContent);
ShareDialog.canShow(shareContent)
.then(function(canShow) {
console.log('canshow', canShow);
if (canShow) {
return ShareDialog.show(shareContent);
} else {
onSuccess();
}
})
.then((result) => {
if (result && result.isCanceled) {
alert("Facebook share cancelled");
}
onSuccess();
})
.catch((error) => {
alert("Facebook share fail with error: " + error);
onSuccess();
})
}

最佳答案

很遗憾,react-native-fbsdk 目前不支持Base64 数据。

https://developers.facebook.com/docs/react-native/faq#faq_631338030360975

其实可以处理over here . buildSharePhoto 方法用于将传入的 JS 数据转换为 SharePhoto 对象。

关于android - react-native-fbsdk - 在 android 上分享照片错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48266559/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com