Skip to content

Commit 6c82c63

Browse files
committed
Added OneSignal Service
1 parent 9c1a6a2 commit 6c82c63

File tree

4 files changed

+52
-8
lines changed

4 files changed

+52
-8
lines changed

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Flutter Core
22

3-
Projelerinizde kullanabileceğiniz çekirdek katman. [ Update: 22.10.2022 ]
3+
Projelerinizde kullanabileceğiniz çekirdek katman. [ Update: 23.10.2022 ]
44

55
#
66

@@ -35,7 +35,6 @@ NOT: Gerekli kütüphaneler yüklü değilse hata alabilirsiniz.
3535
- cloud_firestore
3636
- firebase_auth
3737
- firebase_analytics
38-
- firebase_messaging
3938
- google_sign_in
4039
- Cache Service
4140
- hive
@@ -45,9 +44,12 @@ NOT: Gerekli kütüphaneler yüklü değilse hata alabilirsiniz.
4544
- google_maps_flutter
4645
- geolocator
4746
- geocoding
47+
- Notification Service
48+
- awesome_notifications
49+
- firebase_messaging
50+
- onesignal_flutter
4851
- Other
4952
- path_provider
50-
- awesome_notifications
5153
- screenshot
5254

5355
#
@@ -64,7 +66,6 @@ NOT: Gerekli kütüphaneler yüklü değilse hata alabilirsiniz.
6466
- #### [Realtime Database](https://github.com/cihatyalman/flutter_core/tree/master/lib/core/firebase_services/firebase_database_service.dart)
6567
- #### [Firestore](https://github.com/cihatyalman/flutter_core/tree/master/lib/core/firebase_services/firebase_firestore_service.dart)
6668
- #### [Firebase Auth](https://github.com/cihatyalman/flutter_core/tree/master/lib/core/firebase_services/firebase_auth_service.dart)
67-
- #### [Firebase Push](https://github.com/cihatyalman/flutter_core/tree/master/lib/core/firebase_services/firebase_push_service.dart)
6869
- #### [Firebase Analytics](https://github.com/cihatyalman/flutter_core/tree/master/lib/core/firebase_services/firebase_analytics_service.dart)
6970
- #### [Firebase Google Auth](https://github.com/cihatyalman/flutter_core/tree/master/lib/core/firebase_services/firebase_google_auth_service.dart)
7071

@@ -111,8 +112,10 @@ QR oluşturmak veya qr okumak için kullanabilirsiniz.
111112

112113
#
113114

114-
### Bildirim Servisi:
115+
### Bildirim Servisleri ( [notification_services](https://github.com/cihatyalman/flutter_core/tree/master/lib/core/notification_services) ):
115116

116-
- #### [notification_service](https://github.com/cihatyalman/flutter_core/tree/master/lib/core/notification_service)
117+
- #### [awesome_notification_service](https://github.com/cihatyalman/flutter_core/tree/master/lib/core/notification_service/awesome_notification_service.dart)
118+
- #### [firebase_push_service](https://github.com/cihatyalman/flutter_core/tree/master/lib/core/notification_service/firebase_push_service.dart)
119+
- #### [onesignal_service](https://github.com/cihatyalman/flutter_core/tree/master/lib/core/notification_service/onesignal_service.dart)
117120

118121
#

lib/core/notification_service/notification_service.dart renamed to lib/core/notification_services/awesome_notification_service.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import 'package:awesome_notifications/awesome_notifications.dart';
77
import 'package:flutter/material.dart';
88

9-
final notificationService = NotificationService();
9+
final awesomeNotificationService = AwesomeNotificationService();
1010

11-
class NotificationService {
11+
class AwesomeNotificationService {
1212
final _noti = AwesomeNotifications();
1313
AwesomeNotifications get noti => _noti;
1414

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// https://pub.dev/packages/onesignal_flutter
2+
// https://documentation.onesignal.com/docs/flutter-sdk-setup
3+
4+
// ignore_for_file: avoid_print
5+
6+
import 'package:core_base/core/cache_service/cache_service.dart';
7+
import 'package:onesignal_flutter/onesignal_flutter.dart';
8+
9+
const onesignalId = "YOUR_ONESIGNAL_ID";
10+
11+
class OneSignalService {
12+
init() async {
13+
await OneSignal.shared.consentGranted(true);
14+
OneSignal.shared.setLogLevel(OSLogLevel.verbose, OSLogLevel.none);
15+
await OneSignal.shared.setAppId(onesignalId);
16+
17+
OneSignal.shared.promptUserForPushNotificationPermission().then((accepted) {
18+
print("[C_OneSignal_Accepted]: $accepted");
19+
OneSignal.shared.setSubscriptionObserver((changes) {
20+
print("[C_OneSignal_PlayerId]: ${changes.to.userId}");
21+
cacheService.box.put('playerId', changes.to.userId);
22+
});
23+
24+
// Forground
25+
OneSignal.shared.setNotificationWillShowInForegroundHandler((event) {
26+
print("[C_OneSignal_Foreground_Title]: ${event.notification.title}");
27+
print("[C_OneSignal_Foreground_Body]: ${event.notification.body}");
28+
print(
29+
"[C_OneSignal_Foreground_Data]: ${event.notification.additionalData}");
30+
});
31+
32+
// Opened
33+
OneSignal.shared.setNotificationOpenedHandler((openedResult) {
34+
print("[C_OneSignal_Opened_Title]: ${openedResult.notification.title}");
35+
print("[C_OneSignal_Opened_Body]: ${openedResult.notification.body}");
36+
print(
37+
"[C_OneSignal_Opened_Data]: ${openedResult.notification.additionalData}");
38+
});
39+
});
40+
}
41+
}

0 commit comments

Comments
 (0)