llfbandit / app_links

Android App Links, Deep Links, iOs Universal Links and Custom URL schemes handler for Flutter.
https://pub.dev/packages/app_links
Apache License 2.0
176 stars 68 forks source link

onAppLink not being called on iOS the first time #14

Closed lotusprey closed 2 years ago

lotusprey commented 2 years ago

Problem

While working with the iOS emulator (I don't have a real iOS device, unfortunately), I noticed that onAppLink isn't triggered the first time a deep link is used, but only from the second time onward. Note that in the given example, this behaviour is noticeable only if the app is already running, when the first deep link is used. The issue appears in version 2.2.1 of the package and persists in version 2.2.2. Things are fine in version 2.2.0 though.

Example

pubspec.yaml app_links: ^2.2.2

Info.plist

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLName</key>
        <string>example</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>app</string>
        </array>
    </dict>
</array>

main.dart

import 'dart:math';

import 'package:app_links/app_links.dart';
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) => const MaterialApp(home: Page(1));
}

class Page extends StatelessWidget {
  const Page(this.index, {Key? key}) : super(key: key);

  final int index;

  @override
  Widget build(BuildContext context) {
    AppLinks(onAppLink: (_, link) {
      print('received $link');
      Navigator.push(
        context,
        MaterialPageRoute(builder: (_) => Page(index + 1)),
      );
    });

    return Scaffold(
      appBar: AppBar(
        title: Text('Page $index'),
        backgroundColor:
            Colors.primaries[Random().nextInt(Colors.primaries.length)],
      ),
    );
  }
}

terminal command: xcrun simctl openurl booted app://example

The problem isn't only appearing with the command - opening the deep link through the browser has the same behaviour for example.

llfbandit commented 2 years ago

Thanks for the report! I was tired with inconsistencies between Android & iOS. This should be fixed in v3.0.0

evanwherchek commented 1 year ago

Hi, was this issue resolved in v3.0.0? I tried using that version and I'm still getting this error. Thanks!

nikorehnback commented 5 months ago

Using version 3.5.0 and also seeing this. Android works in cold start normally. We are calling getInitialLink in widgets initState.

@evanwherchek have you been able to get it working?