[英]Firebase Remote Config Flutter macOS don't run
I'm trying to use remote config values when I start my app.当我启动我的应用程序时,我正在尝试使用远程配置值。
The objective of this remote config is get the "url" and "key" of my db此远程配置的目标是获取我的数据库的“url”和“key”
This is my main.dart这是我的主要。dart
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Future.wait([
Firebase.initializeApp(),
]);
await RemoteConfig().start();
runApp(ModularApp(
module: AppModule(),
child: const AppWidget(),
));
}
In my main.dart I call the RemoteConfig().start, this call this function in this class在我的 main.dart 中,我调用 RemoteConfig().start,在此 class 中调用此 function
import 'package:firebase_remote_config/firebase_remote_config.dart';
import 'package:flutter/services.dart';
import 'package:flutter_modular/flutter_modular.dart';
class RemoteConfig {
late FirebaseRemoteConfig _firebaseRemoteConfig;
RemoteConfig._internal();
static final RemoteConfig _singleton = RemoteConfig._internal();
factory RemoteConfig() => _singleton;
Future<void> start() async {
_firebaseRemoteConfig = FirebaseRemoteConfig.instance;
await _firebaseRemoteConfig.setConfigSettings(
RemoteConfigSettings(
fetchTimeout: const Duration(seconds: 30),
minimumFetchInterval: const Duration(minutes: 1),
// minimumFetchInterval: const Duration(days: 30),
),
);
await _firebaseRemoteConfig.fetchAndActivate();
}
Future<void> forceFetch() async {
try {
_firebaseRemoteConfig = FirebaseRemoteConfig.instance;
await _firebaseRemoteConfig.setConfigSettings(
RemoteConfigSettings(
fetchTimeout: const Duration(seconds: 30),
minimumFetchInterval: Duration.zero,
),
);
await _firebaseRemoteConfig.fetchAndActivate();
} on PlatformException catch (exception) {
Modular.to.navigate("/error");
throw exception.toString();
} catch (error) {
Modular.to.navigate("/error");
throw ("Erro ao buscar Configuração Remota");
}
}
getValueOrDefault({
required String key,
required dynamic defaultValue,
}) {
switch (defaultValue.runtimeType) {
case String:
var firebaseValue = _firebaseRemoteConfig.getString(key);
return firebaseValue != "" ? firebaseValue : defaultValue;
case int:
var firebaseValue = _firebaseRemoteConfig.getInt(key);
return firebaseValue != 0 ? firebaseValue : defaultValue;
case bool:
var firebaseValue = _firebaseRemoteConfig.getBool(key);
return firebaseValue != false ? firebaseValue : defaultValue;
case double:
var firebaseValue = _firebaseRemoteConfig.getDouble(key);
return firebaseValue != 0.0 ? firebaseValue : defaultValue;
}
}
}
And, this is the error that I get when I try to run the macOS app (iOS and Android it's okay)而且,这是我尝试运行 macOS 应用程序时遇到的错误(iOS 和 Android 没关系)
Restarted application in 461ms.
flutter: AppModule started!
flutter: -- SplashModule INITIALIZED
flutter: -- HomeModule INITIALIZED
flutter: -- SplashModule DISPOSED
flutter: -- LoginModule INITIALIZED
flutter: -- HomeModule DISPOSED
flutter: [firebase_remote_config/internal] Failed to get installations token. Error : Error Domain=com.firebase.installations Code=0 "Underlying error: The operation couldn’t be completed. SecItemAdd (-34018)" UserInfo={NSLocalizedFailureReason=Underlying error: The operation couldn’t be completed. SecItemAdd (-34018), NSUnderlyingError=0x150998e50 {Error Domain=com.gul.keychain.ErrorDomain Code=0 "SecItemAdd (-34018)" UserInfo={NSLocalizedFailureReason=SecItemAdd (-34018)}}}.
#0 StandardMethodCodec.decodeEnvelope
#1 MethodChannel._invokeMethod
<asynchronous suspension>
#2 MethodChannelFirebaseRemoteConfig.fetchAndActivate
<asynchronous suspension>
#3 FirebaseRemoteConfig.fetchAndActivate
<asynchronous suspension>
#4 Remoteconfig.forceFetch
<asynchronous suspension>
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Erro ao buscar Configuração Remota
#0 Remoteconfig.forceFetch
<asynchronous suspension>
flutter: -- LoginModule DISPOSED
flutter: -- HomeModule INITIALIZED
flutter: -- LoginModule INITIALIZED
flutter: -- HomeModule DISPOSED
flutter:
flutter: -- HomeModule INITIALIZED
flutter: -- LoginModule DISPOSED
Lost connection to device.
Exited
And this is my pubspec.yaml这是我的 pubspec.yaml
environment:
sdk: ">=2.17.0 <3.0.0"
dependencies:
cupertino_icons: ^1.0.5
flutter:
sdk: flutter
flutter_modular: ^5.0.3
mobx: ^2.1.0
flutter_mobx: ^2.0.6+4
shared_preferences: ^2.0.15
url_launcher: ^6.1.5
lottie: ^1.4.3
flutter_svg: ^1.1.5
dio: ^4.0.6
google_fonts: ^3.0.1
appwrite: ^8.1.0
firebase_core: ^1.23.0
firebase_analytics: ^9.3.6
firebase_remote_config: ^2.0.18
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.1
mobx_codegen: ^2.0.7+3
build_runner: ^2.2.1
modular_test: ^2.0.0
flutter_native_splash: ^2.2.10
icons_launcher: ^2.0.5
That error code SecItemAdd (-34018) is regarding keychain sharing entitlements.该错误代码 SecItemAdd (-34018) 与钥匙串共享权利有关。 If you follow these instructions, I believe the error should go away: https://stackoverflow.com/a/38543243/5681607如果您按照这些说明进行操作,我相信错误应该 go 消失: https://stackoverflow.com/a/38543243/5681607
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.