Closed
Description
Bug report
I am able to run an iOS simulator and send notification while in the foreground but this doesn't trigger on a physical device. I configured the firebase messaging for iOS and it just seems to not work.
An example of how I handle notification is below :
Future initialise() async {
if (Platform.isIOS) iOSPermission();
_fcm.getToken().then(onTokenGet);
_fcm.configure(
onMessage: (message) => _notificationMessage(message, context),
onResume: (message) => _notificationMessage(message, context),
onLaunch: (message) => _notificationMessage(message, context),
onBackgroundMessage: myBackgroundMessageHandler,
);
}
void iOSPermission() {
_fcm.requestNotificationPermissions(
IosNotificationSettings(sound: true, badge: true, alert: true));
_fcm.onIosSettingsRegistered.listen((IosNotificationSettings settings) {
print("Settings registered: $settings");
});
}
Future<dynamic> _notificationMessage(
Map<String, dynamic> message, context) async {
print('triggered');
String type;
String notificationType;
bool iOS = Theme.of(context).platform == TargetPlatform.iOS;
if (iOS) {
type = message['type'] ?? null;
notificationType = message['notificationType'];
} else {
type = message['data']['type'] ?? null;
notificationType = message['data']['notificationType'];
}
print(notificationType);
FirestoreService firestore = FirestoreService.instance;
var stream = Provider.of<AuthenticationProvider>(context, listen: false)
.currentUser();
var doc = await stream.first;
Player user = Player.fromJson(doc.data());
print('${user.username} NOTIFICATION MESSAGE ON MESSAGE HANDLER TRIGGERED');
print('notification message handled: ' + message.toString());
if (notificationType == 'teamMatchmakingRedirect') {
_teamMatchmakingNotificationHandler(
message,
type: type,
currentUser: user,
iOS: iOS,
);
} else {
var fromUsername =
iOS ? message['fromUsername'] : message['data']['fromUsername'];
var requestingUserMap = await firestore.fetchDocument(
collectionPath: 'users', documentPath: fromUsername);
Player requestingUser = Player.fromJson(requestingUserMap);
if (notificationType == 'friendsRequest') {
_friendsRequestNotificationHandler(notificationType,
notificationRegular: NotificationRegular.fromJson(
iOS ? Map.from(message) : Map.from(message['data'])),
notificationMessage:
NotificationMessage.fromJson(Map.from(message['notification'])),
type: type,
user: user,
requestingUser: requestingUser,
fromUsername: fromUsername,
firestore: firestore);
} else if (notificationType == 'partnersRequest') {
_partnersRequestNotificationHandler(notificationType,
notificationRegular: NotificationRegular.fromJson(
iOS ? Map.from(message) : Map.from(message['data'])),
notificationMessage:
NotificationMessage.fromJson(Map.from(message['notification'])),
type: type,
user: user,
requestingUser: requestingUser,
fromUsername: fromUsername,
firestore: firestore);
} else if (notificationType == 'gameLobbyQuit') {
NotificationMessage notificationMessage =
NotificationMessage.fromJson(Map.from(message['notification']));
NotificationRegular notificationRegular = NotificationRegular.fromJson(
iOS ? Map.from(message) : Map.from(message['data']));
print('game lobby quit message ' +
notificationMessage.toJson().toString());
print(
'game lobby quit data ' + notificationRegular.toJson().toString());
await showDialog(
context: context,
builder: (_) => notificationView.buildRegularDialog(
notification: notificationMessage,
notificationData: notificationRegular,
isRegularMessage: true,
shouldRedirect: true,
),
);
}
}
}
[✓] Flutter (Channel stable, 1.20.2, on Mac OS X 10.15.4 19E266, locale en-CA)
• Flutter version 1.20.2 at /Users/xcodeclub/flutter
• Framework revision bbfbf1770c (4 weeks ago), 2020-08-13 08:33:09 -0700
• Engine revision 9d5b21729f
• Dart version 2.9.1
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
• Android SDK at /Users/xcodeclub/Library/Android/sdk
• Platform android-30, build-tools 30.0.1
• Java binary at: /Applications/Android
Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build
1.8.0_242-release-1644-b3-6222593)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.6)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.6, Build version 11E708
• CocoaPods version 1.9.3
[✓] Android Studio (version 4.0)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 48.1.2
• Dart plugin version 193.7361
• Java version OpenJDK Runtime Environment (build
1.8.0_242-release-1644-b3-6222593)
[✓] Connected device (1 available)
• iPhone 8 (mobile) • A8FC503F-6E9D-4D27-B3AD-D66A72F3663E • ios •
com.apple.CoreSimulator.SimRuntime.iOS-13-6 (simulator)