url_launcher:对于简单的 URL 方案,canLaunch / launch 在 iOS 上不起作用?

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

我正在使用 url_launcher: ^5.4.10 启动不同的 url 方案,但外部链接在 ios 模拟器上工作正常,但无法打开手机拨号盘和默认电子邮件地址,而在 Android 设备上工作正常

我在ios模拟器上测试过它而不是真实设备

如果我尝试打开拨号盘,这里是例外

{PTS: 6.000 s, decode: 32.021 ms},
]
flutter:  could not launch tel:+18002509646
 

当我尝试打开电子邮箱时,我收到了异常情况

*** First throw call stack:
(
0   CoreFoundation                      0x00000001084f4a2a __exceptionPreprocess + 242
1   libobjc.A.dylib                     0x00000001083874ce objc_exception_throw + 48
2   Foundation                          0x0000000107f2e808 -[__NSConcreteURLComponents initWithString:] + 0
3   CoreServices                        0x000000010f7c2db2 -[_LSURLOverride initWithOriginalURL:checkingForAvailableApplications:] + 136
4   CoreServices                        0x000000010f7c35b5 -[_LSURLOverride initWithOriginalURL:] + 22
5   CoreServices                        0x000000010f7c3d97 _ZN14LaunchServices12URLOverridesL20getURLOverrideCommonEP5NSURL + 374
6   CoreServices                        0x000000010f7c3c10 -[LSApplicationWorkspace(LSURLOverride) URLOverrideForURL:] + 12
7   UIKitCore                   <…>

我的代码网址启动器

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/services.dart';
import 'package:url_launcher/url_launcher.dart';

class Contactcus extends StatelessWidget {
  void customLaunch(command) async {
    if (await canLaunch(command)) {
      await launch(command);
    } else {
      print(' could not launch $command');
    }
  }

  @override
  Widget build(BuildContext context) {

    return Scaffold(
      body: SingleChildScrollView(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Padding(
              padding: EdgeInsets.only(top: 10),
              child: Container(
                child: Column(
                  children: <Widget>[
                    Text(
                      'Contact us'.toUpperCase(),
                      style: TextStyle(
                        fontFamily: 'TT NORMS',
                          fontWeight: FontWeight.w100,
                        fontSize: 25,

                      ),
                    ),
                    Padding(
                      padding: EdgeInsets.only(left: 0),
                      child: Row(
                        children: <Widget>[
                          Expanded(
                            child: SizedBox(
                              child: ListTile(
                                leading: Icon(Icons.phone,
                                    size: 25, color: Colors.black87),
                                onTap: () {
                                  customLaunch('tel:+18001569647');
                                },
                                title: Text(
                                  'Phone'.toUpperCase(),
                                  style: TextStyle(
                                      fontFamily: 'TT NORMS',
                                      fontSize: 20,
                                    fontWeight: FontWeight.w100,

                                  ),
                                ),
                                subtitle: Text(
                                  '1 (800) 250-9646 ',
                                  style: TextStyle(
                                      color: Colors.black87,


                                  ),
                                ),
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),
                    Padding(
                      padding: EdgeInsets.only(left: 0),
                      child: Row(
                        children: <Widget>[
                          Expanded(
                            child: SizedBox(
                              child: ListTile(
                                leading: Icon(Icons.email,
                                    size: 25, color: Colors.black87),
                                onTap: () {
                                  customLaunch(
                                      'mailto:[email protected]?subject=Feed%20back&body=Write your%20feedback');
                                },
                                title: Text(
                                  'Email',
                                  style: TextStyle(
                                      fontFamily: 'TT NORMS',
                                      fontWeight: FontWeight.w100,
                                      fontSize: 20
                                  ),

                                ),
                                subtitle: Text(
                                  '[email protected]',
                                  style: TextStyle(color: Colors.black87,

                                  ),
                                ),
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),
                    Padding(
                      padding: EdgeInsets.only(left: 0),
                      child: Row(
                        children: <Widget>[
                          Expanded(
                            child: SizedBox(
                              child: ListTile(
                                leading: Icon(Icons.location_on,
                                    size: 28, color: Colors.black87),
                                    onTap:(){
                                    customLaunch('https://www.google.ca/maps/place/3434+Cawthra+Rd,+Mississauga,+ON+L5A+2X7/@43.6025224,-79.6147441,17z/data=!3m1!4b1!4m5!3m4!1s0x882b470c94e668ff:0x62c956c363a795d9!8m2!3d43.6025185!4d-79.6125554');
                                    },
                                title: Text(
                                  'MAILING ADDRESS',
                                  style: TextStyle(
                                      fontFamily: 'TT NORMS',
                                      fontWeight: FontWeight.w100,
                                      fontSize: 20

                                  ),
                                ),
                                subtitle: Text(
                                  'Att: Living Hope TV\n'
                                  'Cornerstone Asian Church\n'
                                  '3434 Cawthra Rd\n'
                                  'Mississauga, ON L5A 2X7\n'
                                  'Canada',
                                  style: TextStyle(
                                      color: Colors.black87,

                                  ),
                                ),
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),


                    Padding(
                 padding: EdgeInsets.only(top: 70),
                      child: Row(
                        mainAxisAlignment:MainAxisAlignment.center,
                        children: <Widget>[
                          IconButton(
                            icon: Image.asset('images/youtube.png'),
                            iconSize: 30,
                            onPressed: () {

                       customLaunch('https://www.youtube.com/channel/UCsnohhaCJvkT3prNnMwlvnA');
                            },
                          ),
                          IconButton(
                            icon: Image.asset('images/twitter.png'),
                            iconSize:30,
                                onPressed: () {
                        customLaunch('https://twitter.com/livinghopetv1');

                            },

                          ),
                          IconButton(
                            icon: Image.asset('images/instagram.png'),
                            iconSize: 30,
                                onPressed: () {
                        customLaunch('https://www.instagram.com/livinghopetv/');

                            },

                          ),
                           IconButton(
                            icon: Image.asset('images/facebook.png'),
                            iconSize: 30,
                                onPressed: () {
                        customLaunch('https://www.facebook.com/livinghopetelevision');

                            },


                          ),
                           IconButton(
                            icon: Image.asset('images/web.png'),
                            iconSize: 30,
                                onPressed: () {
                        customLaunch('https://www.livinghopetv.org');

                            },


                          ),

                        ],
                      ),
                    )
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
android ios flutter dart
4个回答
14
投票

如果您想使用外部链接,请将这些行添加到您的

myproject/ios/Runner/Info.plist
文件中。

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>http</string>
    <string>https</string>
</array>

11
投票

我有一个建议,你可以尝试发出这样的命令吗:

检查

1。代码检查

command = "tel://214324234"

// Also, try using Future in place of void
Future<void> customLaunch(command) async {
    if (await canLaunch(command)) {
      await launch(command);
    } else {
      print(' could not launch $command');
    }
  }

2。格式检查:一定要检查一下,如果

tel:
<phone number>
之间没有空格,那就必须写无空格,即
tel:<phone_number>

3.更新检查:另外,还有一个新的更新,即

5.5.0
,请在您的
pubspec.yaml
文件中相应地升级您的软件包。为什么,我告诉你,因为有时以前的版本不支持你的移动平台中的某些功能

4。真实设备检查: 有时会发生模拟器不支持某些功能的情况。我请求你拿到一个真正的

iOS Device
,并检查一下。如果上述方法不能解决您的问题,这可能可以解决问题


1
投票

这对我有用:

import 'dart:io' show Platform;
/// Dial
  Future<void> contactDial(String number) async {
    await _launchCaller(number);
  }

  _launchCaller(String number) async {
    String url = Platform.isIOS ? 'tel://$number' : 'tel:$number';
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw 'Could not launch $url';
    }
  }

0
投票

确保您已将 LSApplicationQueriesSchemes 键添加到您的文件中,其中的数组值包含您要打开的 URL 方案。例如:

<key>LSApplicationQueriesSchemes</key> 
<array> 
  <string>googlechrome</string> 
  <string>googlechromes</string> 
  <string>http</string> 
  <string>https</string> 
</array>

来源

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