gpt4 book ai didi

flutter - FirebaseDynamicLinks getInitialLink() 多次触发

转载 作者:行者123 更新时间:2023-12-04 15:18:00 24 4
gpt4 key购买 nike

getInitialLink() 在第一次检索后继续提供有效的动态链接。
这会导致一个循环,用户被不断强制进入与
深层链接。

Running `flutter doctor --verbose` produced the below results.

[✓] Flutter (Channel stable, 1.20.4, on Mac OS X 10.15.6 19G2021, locale en-US)
• Flutter version 1.20.4 at /Users/sjsam/Documents/Developement/flutter
• Framework revision fba99f6cf9 (5 days ago), 2020-09-14 15:32:52 -0700
• Engine revision d1bc06f032
• Dart version 2.9.2


[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /Users/sjsam/Library/Android/sdk
• Platform android-29, build-tools 28.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.7)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.7, Build version 11E801a
• CocoaPods version 1.9.0

[✓] Android Studio (version 3.6)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 44.0.2
• Dart plugin version 192.7761
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

[✓] Connected device (2 available)
• AOSP on IA Emulator (mobile) • emulator-5554 • android-x86 • Android 9 (API 28) (emulator) # No issues here
• Android SDK built for x86 (mobile) • emulator-5556 • android-x86 • Android 8.0.0 (API 26) (emulator) # Issue happens here

• No issues found!
我的代码示例(主要是文档中给出的代码的副本)如下所示。
 @override
void initState() {
super.initState();
this.initDynamicLinks();
}
void initDynamicLinks() async {
try {
FirebaseDynamicLinks.instance.onLink(onSuccess: (PendingDynamicLinkData dynamicLink) async {
var deepLink = dynamicLink?.link?.toString() ?? null;
if (null != deepLink ) {
var lastIndex = deepLink.lastIndexOf(RegExp(r'/'));
assert(lastIndex != -1, "Problematic Link");
var feedId = deepLink.substring(lastIndex + 1);
// get the required data using feedID
try {
await Navigator.of(this.context).pushNamedAndRemoveUntil(
DeliveryTakeOrder.page,
ModalRoute.withName(PAGENAME),
arguments: argumentsConstructor(/*Arguments Here*/),
);
} catch (e) {
if (!kReleaseMode) {
debugPrint(e.toString());
}
}
}
}, onError: (OnLinkErrorException e) async {
print('onLinkError');
print(e.message);
});
} catch (e, s) {
print(s);
}

// await FirebaseDynamicLinks.instance.
final PendingDynamicLinkData dynamicLink = await FirebaseDynamicLinks.instance.getInitialLink();

var deepLink = dynamicLink?.link?.toString() ?? null;
if (null != deepLink ) {
// A bit of reverse engineering here
var lastIndex = deepLink.lastIndexOf(RegExp(r'/'));
assert(lastIndex != -1, "Problematic Link");
var feedId = deepLink.substring(lastIndex + 1);
// get the required data using feedID
try {
await Navigator.of(this.context).pushNamedAndRemoveUntil(
DeliveryTakeOrder.page,
ModalRoute.withName(PAGENAME),
arguments: argumentsConstructor(/*Arguments Here*/),
);
} catch (e) {
if (!kReleaseMode) {
debugPrint(e.toString());
}
}
}
}
在内联文档中,我看到以下评论。
  /// Attempts to retrieve the dynamic link which launched the app.
///
/// This method always returns a Future. That Future completes to null if
/// there is no pending dynamic link or any call to this method after the
/// the first attempt.
Future<PendingDynamicLinkData> getInitialLink() async {
//..
}
因此,在到达 getInitialLink() 时第二次,它应该返回 null这不是这里的情况。任何帮助表示赞赏。
备注 :在 Android API 级别 27 之前观察到此问题。

最佳答案

截至目前,这是一个持续存在的问题,我可以从 here 确认
我设法使用 shared preferences 解决了这个问题(暂时)
模块。
内部主要:

void main() async {
WidgetsFlutterBinding.ensureInitialized();
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setBool('just_opening', true);
runApp(YourAppName());
}
initState() , 检查持久值 just_opening , 调用 initDynamicLinks然后设置 just_opening归因于 false .
SharedPreferences.getInstance().then((prefs) async{
if(prefs.getBool('just_opening')){
this.initDynamicLinks();
}
await prefs.setBool('just_opening', false);
});
这当然看起来像一个丑陋的黑客,但它适用于 iOS 和 Android。

关于flutter - FirebaseDynamicLinks getInitialLink() 多次触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63986354/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com