73 lines
2.5 KiB
Dart
73 lines
2.5 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:firebase_core/firebase_core.dart';
|
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import '../../app_initalizer.dart';
|
|
|
|
class FirebaseNotificationHandler {
|
|
Future<void> initial() async {
|
|
try {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
await Firebase.initializeApp(
|
|
options: kIsWeb
|
|
? const FirebaseOptions(
|
|
apiKey: "AIzaSyA0HZjKpRuPOi1SC3f_EZTvlS3mcj9UVo0",
|
|
authDomain: "didvan-9b7da.firebaseapp.com",
|
|
projectId: "didvan-9b7da",
|
|
storageBucket: "didvan-9b7da.appspot.com",
|
|
messagingSenderId: "935017686266",
|
|
appId: "1:935017686266:web:a93f7a19bed23c51d2d543",
|
|
measurementId: "G-80B4H9E8Y0")
|
|
: Platform.isAndroid
|
|
? const FirebaseOptions(
|
|
apiKey: 'AIzaSyBp-UHjWeM0H0UHtX5yguFKG-riMzvvCzw',
|
|
appId: '1:935017686266:android:f9cbc9aba8e3d65ed2d543',
|
|
messagingSenderId: '935017686266',
|
|
projectId: 'didvan-9b7da',
|
|
)
|
|
: const FirebaseOptions(
|
|
apiKey: 'AIzaSyCMa-zg_uVhOfTnea5Klz6aPZlgHwVGj7U',
|
|
appId: '1:935017686266:ios:de47638bd662463fd2d543',
|
|
messagingSenderId: '935017686266',
|
|
projectId: 'didvan-9b7da',
|
|
// iosBundleId: "com.didvan.didvanapp",
|
|
// storageBucket: "didvan-9b7da.appspot.com",
|
|
// iosClientId:
|
|
// "935017686266-54hu01v9cc5pqpgofo1gk2n3hegj4r2m.apps.googleusercontent.com"
|
|
),
|
|
);
|
|
final initMsg = await FirebaseMessaging.instance.getInitialMessage();
|
|
if (initMsg != null) {
|
|
AppInitializer.clickAction = initMsg.data['click_action'].replaceAll(
|
|
'navigate-',
|
|
'',
|
|
);
|
|
}
|
|
|
|
// LocalNotificationService.initialize();
|
|
|
|
NotificationSettings settings =
|
|
await FirebaseMessaging.instance.requestPermission(
|
|
alert: true,
|
|
announcement: false,
|
|
badge: true,
|
|
carPlay: false,
|
|
criticalAlert: false,
|
|
provisional: false,
|
|
sound: true,
|
|
);
|
|
|
|
debugPrint(
|
|
'User granted notifications permission: ${settings.authorizationStatus}');
|
|
} catch (e) {
|
|
if (kDebugMode) {
|
|
print(e.toString());
|
|
}
|
|
}
|
|
}
|
|
}
|