【问题标题】:Flutter url_launcher open Facebook link inside app(Facebook) installed but in IOS it just open facebook and not the linkFlutter url_launcher 在已安装的应用程序(Facebook)中打开 Facebook 链接,但在 IOS 中它只打开 facebook 而不是链接
【发布时间】:2020-07-08 09:18:21
【问题描述】:

我使用了 Url_launcher 包;如果应用程序安装在浏览器中,我想在 Facebook 应用程序中打开 Facebook 链接。这在 Android 中很好用,但在 IOS 中它只打开 Facebook 应用程序而不是链接。

代码是:

String digital_url= "https://facebook.com/AliForDigitalIsrael/";

    new ListTile(
                            leading: new SvgPicture.asset(
                              'assets/images/ic_menu_fb.svg',
                              height: 24.0,
                              width: 24.0,
                              color: Colors.black54,
                            ),
                            title: new Text(
                              Strings.fbdigital,
                              textDirection: TextDirection.rtl,
                            ),
                            onTap: () async {
                              var fbUrl =
                                  "fb://facewebmodal/f?href=" + Strings.digital_url;
                              launchFacebook(fbUrl, Strings.digital_url);
                              hideDrawer();
                            },
    
                          ),
         Future<void> launchFacebook(String fbUrl,String fbWebUrl)
      async {
        try {
          bool launched = await launch(fbUrl, forceSafariVC: false);
          print("Launched Native app $launched");
    
          if (!launched) {
            await launch(fbWebUrl, forceSafariVC: false);
            print("Launched browser $launched");
          }
        } catch (e) {
          await launch(fbWebUrl, forceSafariVC: false);
          print("Inside catch");
        }
      }

【问题讨论】:

  • 您是否为 iOS 编辑了 info.plist 文件?您必须为 iOS 设置 URL 方案才能使深层链接正常工作。
  • @danypata 不,我没有这样做,你能分享给我任何重新评分的链接吗?
  • @danypata 我不明白。您能否提供其他链接或解决方案。

标签: flutter dart flutter-test flutter-packages flutter-ios


【解决方案1】:

我的工作职能:

void _launchSocial(String url, String fallbackUrl) async {
  // Don't use canLaunch because of fbProtocolUrl (fb://)
  try {
    bool launched =
        await launch(url, forceSafariVC: false, forceWebView: false);
    if (!launched) {
      await launch(fallbackUrl, forceSafariVC: false, forceWebView: false);
      }
  } catch (e) {
    await launch(fallbackUrl, forceSafariVC: false, forceWebView: false);
  }
}

然后在 onPressed 或 onTab:

_launchSocial('fb://profile/408834569303957', 'https://www.facebook.com/dorockxl')

不要忘记将 fbYOURPAGEID 添加到 Info.plist 中的 CFBundleURLSchemes 数组中:

注意:您可以使用https://lookup-id.com 来查找您的页面ID

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>fb408834569303957</string>
        </array>
    </dict>
</array>

顺便说一句,您无需额外设置即可将此方法用于 Twitter 和 Instagram。网址足以打开这些原生应用:

_launchSocial('https://www.instagram.com/YOURNAME/', '')

_launchSocial('https://twitter.com/YOURNAME', '')

【讨论】:

  • 您使用哪个插件来启动 url?因为上面的代码给我一个错误。 “错误:找不到方法:'启动'。”
  • 我在 Flutter 1.20.1 上使用了 url_launcher: ^5.5.0。 Flutter 是新的,因此版本可能会有很大差异。
猜你喜欢
  • 2019-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-12
  • 2022-09-29
  • 1970-01-01
相关资源
最近更新 更多