我正在使用https://docs.expo.dev/versions/latest/sdk/sharing/创建与当前屏幕截图共享按钮。
这是我的代码片段,运行良好。
import ViewShot from "react-native-view-shot";
import * as Sharing from "expo-sharing";
const viewShot = React.useRef();
let captureAndShareScreenshot = () => {
try {
viewShot.current.capture().then((uri) => {
console.log("do something with ", uri);
const options = {
mimeType: 'image/jpeg',
dialogTitle: "Check Awesome quotes Check Awesome quotesCheck Awesome quotesCheck Awesome quotesCheck Awesome quotesCheck Awesome quotesCheck Awesome quotesCheck Awesome quotesCheck Awesome quotesCheck Awesome quotesCheck Awesome quotesCheck Awesome quotesCheck Awesome quotes",
};
Sharing.shareAsync("file://" + uri, options); // this is causing error for second time share
}), (error) => console.error("Oops, snapshot failed", error);
} catch (e) {
console.log(e);
}
};
<ViewShot style={styles.container} ref={viewShot} options={{ format: "jpg", quality: 0.9, }}>
<TouchableOpacity style={styles.bubbleIcons} onPress={captureAndShareScreenshot} >
<Image source={require("./assets/share.png")} style={styles.iconImage} />
</TouchableOpacity >
</ViewShot>
唯一的问题是,一旦屏幕截图被共享,然后回到应用程序后,再次共享时,它会给出错误
Possible Unhandled Promise Rejection (id: 1):
Error: Call to function 'ExpoSharing.shareAsync' has been rejected.
→ Caused by: Another share request is being processed now.
Error: Call to function 'ExpoSharing.shareAsync' has been rejected.
→ Caused by: Another share request is being processed now.
文档中没有任何内容可用于取消当前请求或检查首次共享是否成功。
1条答案
按热度按时间eeq64g8w1#
example对我来说就像预期的那样工作。