[英]Launch app from share button in iOS - Objective C and React Native
[英]React Native and iOS share button
我正在尝试访问 iOS 的共享按钮,您可以在其中将内容共享到所有服务,包括消息等......知道我该怎么做吗? 谢谢
您可能想签出react-native-share软件包,它应该涵盖您的用例。 您还可以在JS.Coach上查看更多相关的软件包
您可以在React Native中开箱即用-只需使用ActionSheetIOS.showShareActionSheetWithOptions
。 请参阅此处的文档。
现在,您可以在react-native中使用一个简单的Share API。
import { Share } from "react-native"
Share.share(
{
title: "a title",
message: "some message",
// or
url: imageReference
},
(options)
);
这比你想象的要容易得多。 进一步添加到@MoOx 答案。
使用新的共享 api,您可以轻松地与 React Native 应用程序共享信息,只需将其与所有变量和配置一起使用即可。 (见这里)
import React from 'react';
import { Share, View, Button } from 'react-native';
const ShareExample = () => {
const onShare = async () => {
try {
const result = await Share.share({
message:
'React Native | A framework for building native apps using React',
});
if (result.action === Share.sharedAction) {
if (result.activityType) {
// shared with activity type of result.activityType
} else {
// shared
}
} else if (result.action === Share.dismissedAction) {
// dismissed
}
} catch (error) {
alert(error.message);
}
};
return (
<View style={{ marginTop: 50 }}>
<Button onPress={onShare} title="Share" />
</View>
);
};
export default ShareExample;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.