如何在不渲染mainInterface.storyboard的情况下使用react-native-share-menu

问题描述 投票:0回答:3

我刚刚将react-native-share-menu添加到我的项目中,一切都按预期进行。但我想从共享菜单打开我的应用程序而不显示对话框模式(附图)。仅在 iOS 上显示。 enter image description here

我将 didSelectPost() 添加到 viewDidLoad() 中,之后它可以在模拟器上运行,但不能在真实设备上运行。

   override func viewDidLoad() {
super.viewDidLoad()

if let hostAppId = Bundle.main.object(forInfoDictionaryKey: HOST_APP_IDENTIFIER_INFO_PLIST_KEY) as? String {
  self.hostAppId = hostAppId
} else {
  print("Error: \(NO_INFO_PLIST_INDENTIFIER_ERROR)")
}

if let hostAppUrlScheme = Bundle.main.object(forInfoDictionaryKey: HOST_URL_SCHEME_INFO_PLIST_KEY) as? String {
  self.hostAppUrlScheme = hostAppUrlScheme
} else {
  print("Error: \(NO_INFO_PLIST_URL_SCHEME_ERROR)")
}
didSelectPost() //call post function 

}

react-native react-native-ios
3个回答
3
投票

您需要创建自己的共享扩展,即使它只是您进入应用程序之前的占位符。确保您已严格遵循这些说明:

https://github.com/meedan/react-native-share-menu/blob/master/SHARE_EXTENSION_VIEW.md

完成此操作后,将显示您在index.share.js中注册的“MyShareComponent”,而不是您在帖子中提到的对话框模式。

AppRegistry.registerComponent(
  "ShareMenuModuleComponent",
  () => MyShareComponent
);

在该组件内,您可以显示自己的自定义共享对话框,或者在安装后简单地重定向到主应用程序,如下所示:

useEffect(() => {
  ShareMenuReactView.data().then(({mimeType, data}) => {
    ShareMenuReactView.continueInApp({shareInfo: data});
  });
}, []);

我已经成功使用此方法实现了我自己的共享对话框,并直接重定向到应用程序。


2
投票

您可以通过自行修改

ShareViewController.swift
来绕过共享窗口。

override func configurationItems() -> [Any]! {
      didSelectPost()
      return nil
    }

0
投票

我刚刚想通了这一点。 看看我在他们的 github 上的回答

© www.soinside.com 2019 - 2024. All rights reserved.