Skip to content

Commit ac682f2

Browse files
authored
fix: Push notification in iOS not working (#940)
1 parent bae8902 commit ac682f2

File tree

5 files changed

+73
-18
lines changed

5 files changed

+73
-18
lines changed

packages/flutter/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [5.1.1](https://github.com/parse-community/Parse-SDK-Flutter/compare/flutter-5.1.0...flutter-5.1.1) (2023-06-28)
2+
3+
### Bug Fixes
4+
5+
* Push notifications in iOS not working; this changes the dependency in `ParseNotification` from `awesome_notifications` to `flutter_local_notifications` ([#940](https://github.com/parse-community/Parse-SDK-Flutter/pull/940))
6+
17
## [5.1.0](https://github.com/parse-community/Parse-SDK-Flutter/compare/flutter-5.0.1...flutter-5.1.0) (2023-05-22)
28

39
### Features

packages/flutter/lib/parse_server_sdk_flutter.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import 'dart:async';
55
import 'dart:io';
66
import 'dart:math';
77
import 'dart:ui';
8-
import 'package:awesome_notifications/awesome_notifications.dart';
98
import 'package:connectivity_plus/connectivity_plus.dart';
109
import 'package:flutter/foundation.dart';
1110
import 'package:flutter/material.dart';
@@ -15,6 +14,7 @@ import 'package:parse_server_sdk_flutter/src/storage/core_store_directory_io.dar
1514
if (dart.library.html) 'package:parse_server_sdk_flutter/src/storage/core_store_directory_web.dart';
1615
import 'package:sembast/sembast.dart';
1716
import 'package:shared_preferences/shared_preferences.dart';
17+
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
1818

1919
export 'package:parse_server_sdk/parse_server_sdk.dart'
2020
hide Parse, CoreStoreSembastImp;

packages/flutter/lib/src/notification/parse_notification.dart

+53-15
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,68 @@ class ParseNotification {
55
static final ParseNotification instance = ParseNotification._internal();
66
static String keyNotificationChannelName = "parse";
77

8+
final FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
9+
FlutterLocalNotificationsPlugin();
10+
11+
AndroidInitializationSettings? _androidNotificationSettings;
12+
DarwinInitializationSettings? _iOSNotificationSettings;
13+
DarwinInitializationSettings? _macOSNotificationSettings;
14+
LinuxInitializationSettings? _linuxNotificationSettings;
15+
816
factory ParseNotification() {
917
return instance;
1018
}
1119

1220
ParseNotification._internal() {
13-
// Initialize notifications helper package
14-
AwesomeNotifications().initialize(
15-
null,
16-
[
17-
NotificationChannel(
18-
channelKey: keyNotificationChannelName,
19-
channelName: keyNotificationChannelName,
20-
channelDescription: 'Notification channel for parse')
21-
],
21+
_initialize();
22+
}
23+
24+
setNotificationSettings(
25+
{AndroidInitializationSettings? androidNotificationSettings,
26+
DarwinInitializationSettings? iOSNotificationSettings,
27+
DarwinInitializationSettings? macOSNotificationSettings,
28+
LinuxInitializationSettings? linuxNotificationSettings}) {
29+
_androidNotificationSettings = androidNotificationSettings;
30+
_iOSNotificationSettings = iOSNotificationSettings;
31+
_macOSNotificationSettings = macOSNotificationSettings;
32+
_linuxNotificationSettings = linuxNotificationSettings;
33+
}
34+
35+
/// Initialize notification helper
36+
Future<void> _initialize() async {
37+
InitializationSettings initializationSettings = InitializationSettings(
38+
android: _androidNotificationSettings ??
39+
const AndroidInitializationSettings('launch_background'),
40+
iOS: _iOSNotificationSettings,
41+
linux: _linuxNotificationSettings,
42+
macOS: _macOSNotificationSettings);
43+
44+
AndroidNotificationChannel channel = AndroidNotificationChannel(
45+
keyNotificationChannelName, // id
46+
keyNotificationChannelName, // title
47+
importance: Importance.max,
2248
);
49+
50+
await _flutterLocalNotificationsPlugin.initialize(initializationSettings);
51+
52+
await _flutterLocalNotificationsPlugin
53+
.resolvePlatformSpecificImplementation<
54+
AndroidFlutterLocalNotificationsPlugin>()
55+
?.createNotificationChannel(channel);
2356
}
2457

2558
/// Show notification
2659
void showNotification(title) {
27-
AwesomeNotifications().createNotification(
28-
content: NotificationContent(
29-
id: Random().nextInt(1000),
30-
channelKey: keyNotificationChannelName,
31-
title: title,
32-
));
60+
_flutterLocalNotificationsPlugin.show(
61+
Random().nextInt(1000),
62+
title,
63+
null,
64+
NotificationDetails(
65+
android: AndroidNotificationDetails(
66+
keyNotificationChannelName,
67+
keyNotificationChannelName,
68+
// other properties...
69+
),
70+
));
3371
}
3472
}

packages/flutter/lib/src/push/parse_push.dart

+11
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,18 @@ class ParsePush {
1717
Future<void> initialize(
1818
firebaseMessaging, {
1919
String? vapidKey,
20+
AndroidInitializationSettings? androidNotificationSettings,
21+
DarwinInitializationSettings? iOSNotificationSettings,
22+
DarwinInitializationSettings? macOSNotificationSettings,
23+
LinuxInitializationSettings? linuxNotificationSettings,
2024
}) async {
25+
// Parse Notification settings
26+
ParseNotification.instance.setNotificationSettings(
27+
androidNotificationSettings: androidNotificationSettings,
28+
iOSNotificationSettings: iOSNotificationSettings,
29+
linuxNotificationSettings: linuxNotificationSettings,
30+
macOSNotificationSettings: macOSNotificationSettings);
31+
2132
// Get Google Cloud Messaging (GCM) token
2233
firebaseMessaging
2334
.getToken(vapidKey: vapidKey)

packages/flutter/pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: parse_server_sdk_flutter
22
description: The Flutter SDK to connect to Parse Server. Build your apps faster with Parse Platform, the complete application stack.
3-
version: 5.1.0
3+
version: 5.1.1
44
homepage: https://github.com/parse-community/Parse-SDK-Flutter
55

66
environment:
@@ -26,7 +26,7 @@ dependencies:
2626
# Utils
2727
path_provider: ^2.0.15
2828
package_info_plus: ^4.0.2
29-
awesome_notifications: ^0.7.4+1
29+
flutter_local_notifications: ^14.1.1
3030
path: ^1.8.2
3131

3232
dev_dependencies:

0 commit comments

Comments
 (0)