Skip to content

fix: Push notifications in iOS not working #940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [5.1.1](https://github.com/parse-community/Parse-SDK-Flutter/compare/flutter-5.1.0...flutter-5.1.1) (2023-06-28)

### Bug Fixes

* 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))

## [5.1.0](https://github.com/parse-community/Parse-SDK-Flutter/compare/flutter-5.0.1...flutter-5.1.0) (2023-05-22)

### Features
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/parse_server_sdk_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'dart:async';
import 'dart:io';
import 'dart:math';
import 'dart:ui';
import 'package:awesome_notifications/awesome_notifications.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
Expand All @@ -15,6 +14,7 @@ import 'package:parse_server_sdk_flutter/src/storage/core_store_directory_io.dar
if (dart.library.html) 'package:parse_server_sdk_flutter/src/storage/core_store_directory_web.dart';
import 'package:sembast/sembast.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';

export 'package:parse_server_sdk/parse_server_sdk.dart'
hide Parse, CoreStoreSembastImp;
Expand Down
68 changes: 53 additions & 15 deletions packages/flutter/lib/src/notification/parse_notification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,68 @@ class ParseNotification {
static final ParseNotification instance = ParseNotification._internal();
static String keyNotificationChannelName = "parse";

final FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();

AndroidInitializationSettings? _androidNotificationSettings;
DarwinInitializationSettings? _iOSNotificationSettings;
DarwinInitializationSettings? _macOSNotificationSettings;
LinuxInitializationSettings? _linuxNotificationSettings;

factory ParseNotification() {
return instance;
}

ParseNotification._internal() {
// Initialize notifications helper package
AwesomeNotifications().initialize(
null,
[
NotificationChannel(
channelKey: keyNotificationChannelName,
channelName: keyNotificationChannelName,
channelDescription: 'Notification channel for parse')
],
_initialize();
}

setNotificationSettings(
{AndroidInitializationSettings? androidNotificationSettings,
DarwinInitializationSettings? iOSNotificationSettings,
DarwinInitializationSettings? macOSNotificationSettings,
LinuxInitializationSettings? linuxNotificationSettings}) {
_androidNotificationSettings = androidNotificationSettings;
_iOSNotificationSettings = iOSNotificationSettings;
_macOSNotificationSettings = macOSNotificationSettings;
_linuxNotificationSettings = linuxNotificationSettings;
}

/// Initialize notification helper
Future<void> _initialize() async {
InitializationSettings initializationSettings = InitializationSettings(
android: _androidNotificationSettings ??
const AndroidInitializationSettings('launch_background'),
iOS: _iOSNotificationSettings,
linux: _linuxNotificationSettings,
macOS: _macOSNotificationSettings);

AndroidNotificationChannel channel = AndroidNotificationChannel(
keyNotificationChannelName, // id
keyNotificationChannelName, // title
importance: Importance.max,
);

await _flutterLocalNotificationsPlugin.initialize(initializationSettings);

await _flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.createNotificationChannel(channel);
}

/// Show notification
void showNotification(title) {
AwesomeNotifications().createNotification(
content: NotificationContent(
id: Random().nextInt(1000),
channelKey: keyNotificationChannelName,
title: title,
));
_flutterLocalNotificationsPlugin.show(
Random().nextInt(1000),
title,
null,
NotificationDetails(
android: AndroidNotificationDetails(
keyNotificationChannelName,
keyNotificationChannelName,
// other properties...
),
));
}
}
11 changes: 11 additions & 0 deletions packages/flutter/lib/src/push/parse_push.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,18 @@ class ParsePush {
Future<void> initialize(
firebaseMessaging, {
String? vapidKey,
AndroidInitializationSettings? androidNotificationSettings,
DarwinInitializationSettings? iOSNotificationSettings,
DarwinInitializationSettings? macOSNotificationSettings,
LinuxInitializationSettings? linuxNotificationSettings,
}) async {
// Parse Notification settings
ParseNotification.instance.setNotificationSettings(
androidNotificationSettings: androidNotificationSettings,
iOSNotificationSettings: iOSNotificationSettings,
linuxNotificationSettings: linuxNotificationSettings,
macOSNotificationSettings: macOSNotificationSettings);

// Get Google Cloud Messaging (GCM) token
firebaseMessaging
.getToken(vapidKey: vapidKey)
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: parse_server_sdk_flutter
description: The Flutter SDK to connect to Parse Server. Build your apps faster with Parse Platform, the complete application stack.
version: 5.1.0
version: 5.1.1
homepage: https://github.com/parse-community/Parse-SDK-Flutter

environment:
Expand All @@ -26,7 +26,7 @@ dependencies:
# Utils
path_provider: ^2.0.15
package_info_plus: ^4.0.2
awesome_notifications: ^0.7.4+1
flutter_local_notifications: ^14.1.1
path: ^1.8.2

dev_dependencies:
Expand Down