重定向到应用商店在 Flutter

j9per5c4  于 2023-04-07  发布在  Flutter
关注(0)|答案(4)|浏览(231)

我尝试在我的应用程序中启动一个链接,所以当用户单击按钮时,它会重定向到appstore。下面是部分代码:

InkWell(
                                onTap: () =>launchapp(),
                                child: Text(
                                        "Update",
                                        style: TextStyle(
                                            fontSize: 17),
                                      )
                              )

launchapp() async {
    try {
      if (await canLaunch('https://apps.apple.com/app/MyAppName/idXXXXX')) {
        await launch(url);
      } else {
        throw 'Could not launch $url';
      }
    } catch (e) {
      print(e);
    }
  }

我在我的模拟器中尝试过,但总是

safari cannot open the page because the address is invalid

有办法解决吗?

czfnxgou

czfnxgou1#

您可以使用Store_redirect包。

StoreRedirect.redirect(androidAppId: "com.iyaffle.rangoli",
                    iOSAppId: "585027354");
eoxn13cs

eoxn13cs2#

您可以更改DNS服务器并选择手动选项。转到Apple菜单,然后转到系统偏好设置〉网络。一些谷歌公共DNS服务器示例::8.8.8.88.8.4.4我用这种方法解决了同样的问题。

eit6fx6z

eit6fx6z3#

在应用程序上方的AndroidManifest.xml中添加以下依赖项

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />

<queries>
    <intent>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="https" />
    </intent>
    <!-- If your app opens https URLs -->
    <intent>
        <action android:name="android.intent.action.VIEW" />
        <data android:scheme="http" />
    </intent>
    <!-- If your app opens https URLs -->
    <intent>
        <action android:name="android.intent.action.VIEW" />
        <data android:scheme="https" />
    </intent>
</queries>

手机网址

import 'package:flutter/material.dart';
 import 'package:url_launcher/url_launcher.dart';
    
    class MobileUrl extends StatelessWidget {
      const MobileUrl({Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
    
      void  launchapp() async {
          final Uri url = 
         Uri.parse('https://apps.apple.com/app/MyAppName/idXXXXX');
          try {
            if (await canLaunch(url.toString())) {
              await launch(url.toString());
            } else {
              throw 'Could not launch $url';
            }
          } catch (e) {
            print(e);
          }
        }
    
        return Scaffold(
          body: SafeArea(
            child: Center(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                
   
                  ElevatedButton(onPressed: (){
                    launchapp();
                  }, child: Text('Launch app Button'))
    
                ],
              ),
            ),
          ),
        );
      }
    }
nlejzf6q

nlejzf6q4#

launchapp() async {
    try {
      if (await canLaunch("https://apps.apple.com/app/id$appId")) {
        await launch(url);
      } else {
        throw 'Could not launch $url';
      }
    } catch (e) {
      print(e);
    }
  }

$appId是您在App Store的appId。

相关问题