-
Notifications
You must be signed in to change notification settings - Fork 6
Description
I was trying to enbale the firebase push notification in the flutter example app , after uncommenting the code there is an error occurs in the code can you please reivew and check why the issue is coming . below is the code .
@pragma('vm:entry-point')
Future _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
//!!! Method is working in the background isolate!
//!!! At this moment Activity may not exist or whole App could be completely stopped
//!!! Code below initializes Siprix, adds saved accounts and refreshes registration (makes app ready to receive incoming call)
debugPrint("[!!!] Handling a background message id:'${message.messageId}' data:'${message.data}'");
try{
debugPrint("Initialize siprix by push notif");
_MyAppState._initializeSiprix(); // here the error occurs it requires param to pass
debugPrint("Read and add accounts by push notif");
SharedPreferences prefs = await SharedPreferences.getInstance();
String accJsonStr = prefs.getString('accounts') ?? '';
if(accJsonStr.isNotEmpty) {
AppAccountsModel tmpAccsModel = AppAccountsModel();
await tmpAccsModel.loadFromJson(accJsonStr);
tmpAccsModel.refreshRegistration();
}
} on Exception catch (err) {
debugPrint('Error: ${err.toString()}');
}
}
The method used is this requires context
static void _initializeSiprix(BuildContext context,
[LogsModel? logsModel]) async {
debugPrint('Initialize siprix');
InitData iniData = InitData();
iniData.license = "...license-credentials...";
iniData.logLevelFile = LogLevel.debug;
iniData.logLevelIde = LogLevel.info;
//- uncomment if required -//
//iniData.enableVUmeter = true;
//iniData.singleCallMode = false;
//iniData.tlsVerifyServer = false;
if (Platform.isIOS) {
iniData.enableCallKit = true;
iniData.enablePushKit = true; //Enable only when added PushNotif support on server side
iniData.unregOnDestroy = false;
}
if (Platform.isAndroid) {
iniData.unregOnDestroy = false;
iniData.listenTelState = true;
iniData.listenVolChange = true;
iniData.serviceClassName = "com.siprix.voip_sdk_example.MyNotifService";
iniData.singleCallMode = true;
// context
// .read<DevicesModel>()
// .setForegroundMode(true)
// .catchError((e) {}); //set foreground servcie true by default
}
await SiprixVoipSdk().initialize(iniData, logsModel);
//Set video params (if required)
//VideoData vdoData = VideoData();
//vdoData.noCameraImgPath = await MyApp.writeAssetAndGetFilePath("noCamera.jpg");
//vdoData.bitrateKbps = 800;
//SiprixVoipSdk().setVideoParams(vdoData);
//Check the version
//String? version = await SiprixVoipSdk().version();
//debugPrint("Siprix version: $version");
}