iOS 使用 Flutter 制作的应用因无法重现的错误而被拒绝

iOS app made with Flutter rejected due to unreproducible bug

我的应用被 Apple 拒绝,因为某项功能在 iPad (iOS 14.6) 上运行不佳。 我已经检查了代码和 XCode 设置并重新提交了几次,但 Apple 审阅者说它仍然无法在 iPad.

上运行

该应用程序是用 Flutter 制作的。有问题的功能是通过 sqflite 实现的,它从本地数据库读取存储的数据。 就代码而言,似乎snapshot.hasDataFutureBuilderbuilder属性中仍然是false,而应该是true

但是,当我在 iPad/iPhone 模拟器上调试运行时它工作正常。 (我没有实际的 iPhone 和 iPad,所以我无法使用 TestFlight 检查)
应用程序的 Android 版本已经在 Google Play Store,它在 Android 设备上运行良好。

我不确定哪里出了问题,但我怀疑以下几点;

想知道有没有人在苹果评论上遇到过同样的问题,或者有没有人了解更多。

flutter doctor -v的输出和出现bug的代码如下

flutter doctor -v

[✓] Flutter (Channel beta, 2.2.0, on macOS 11.4 20F71 darwin-x64, locale en-JP)
    • Flutter version 2.2.0 at /Users/xxx/development/flutter
    • Framework revision b22742018b (2 weeks ago), 2021-05-14 19:12:57 -0700
    • Engine revision a9d88a4d18
    • Dart version 2.13.0

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at /Users/xxx/Library/Android/sdk
    • Platform android-30, build-tools 30.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.5, Build version 12E262
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)

[✓] VS Code (version 1.52.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.18.0

[✓] Connected device (2 available)
    • iPad (8th generation) (mobile) • CA6F44F0-33C5-421B-A7D4-5A73832AE926 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator)
    • Chrome (web)                   • chrome                               • web-javascript • Google Chrome 91.0.4472.77

• No issues found!
child: FutureBuilder(
  future: _itemList, // List that is loaded by databaseHelper's Read method
  builder: (_, snapshot) {
    if (!snapshot.hasData) {
      return Center(
        child: CircularProgressIndicator(), // Apple reviewer says it shows infinately.
      );
    } else if (snapshot.data.length >= 1) {
      return ListView.builder(
        itemCount: snapshot.data.length,
        itemBuilder: (_, int index) {
          return _buildItems(snapshot.data[index]); // This method returns the list of items.
        },
      );
    } else {
      return Text('no data');
    }
  },
),

感谢您的帮助!此问题已解决。
原因是_initDb方法生成的路径错误

之前:

Future<Database> _initDb() async {
  Directory dir = await getApplicationDocumentsDirectory();
  String path = dir.path +
      'items_table.db'; 
  final itemsDb =
      await openDatabase(path, version: 1, onCreate: _createDb);
  return itemsDb;
}

print(path);此时,
Android: /data/user/0/com.example.app_name/app_flutteritems_table.db
-> 虽然路径不正确,但它在实际 Android 设备上运行良好。
iOS: /var/mobile/Containers/Data/Application/XXXXXX-XXXXX/Documentsitems_table.db
-> 在 snapshot.hasError == true.

的情况下,这会导致 DatabaseException(open_failed) 作为输出

要解决此问题,请修改代码以便生成正确的路径。
我在数据库名称的字符串前添加了/

Future<Database> _initDb() async {
  Directory dir = await getApplicationDocumentsDirectory();
  String path = dir.path +
      '/items_table.db'; 
  final itemsDb =
      await openDatabase(path, version: 1, onCreate: _createDb);
  return itemsDb;
}

然后,生成正确的路径。
Android: /data/user/0/com.example.app_name/app_flutter/items_table.db
iOS: /var/mobile/Containers/Data/Application/XXXXXX-XXXXX/Documents/items_table.db