我处理深度链接并根据文档进行集成,但是当使用应用程序或浏览器打开添加 url 对话框时,这是我的功能,universal_link 的这两个函数,我在 mainfest 文件中添加了集成主机和方案:-
Future<void> initDynamicLinks() async {
FirebaseDynamicLinks.instance.onLink(
onSuccess: (PendingDynamicLinkData dynamicLink) async {
final Uri deepLink = dynamicLink?.link;
if (deepLink != null) {
// ignore: unawaited_futures
Navigator.pushNamed(context, deepLink.path);
}
_createDynamicLink(false);
}, onError: (OnLinkErrorException e) async {
print('onLinkError');
print(e.message);
});
final PendingDynamicLinkData data =
await FirebaseDynamicLinks.instance.getInitialLink();
final Uri deepLink = data?.link;
if (deepLink != null) {
// ignore: unawaited_futures
Navigator.pushNamed(context, deepLink.path);
}
}
Future<void> _createDynamicLink(bool short) async {
setState(() {
_isCreatingLink = true;
});
final DynamicLinkParameters parameters = DynamicLinkParameters(
uriPrefix: 'https://emtahnatapp.page.link',
link: Uri.parse('https://emtahnatapp.page.link/iho8'),
androidParameters: AndroidParameters(
packageName: 'com.emtahnatapp.eg',
minimumVersion: 100,
),
// iosParameters: IosParameters(
// bundleId: 'com.google.FirebaseCppDynamicLinksTestApp.dev',
// minimumVersion: '0',
// ),
);
Uri url;
if (short) {
final ShortDynamicLink shortLink = await parameters.buildShortLink();
url = shortLink.shortUrl;
} else {
url = await parameters.buildUrl();
}
setState(() {
_linkMessage = url.toString();
_isCreatingLink = false;
});
}
}