Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Xamarin.Firebase.IOS.CloudMessaging receive FCM token but notifications not working #418

Open
davidtabor90 opened this issue Jun 4, 2020 · 6 comments

Comments

@davidtabor90
Copy link

Hi,

I'm new in Firebase Cloud Messaging and I trying to use it with our Xamarin.iOS app.

I generate application in Firebase and set all certificates, ids, etc.
Than I add nuget to project, GoogleService-Info.plist, enable Background mode - Remote notification in Entitlements.plist, enable Push notification in Info.plist.

I'm calling method at AppDelegate.FinishedLaunching for init remote notification. Than I get fcm token but if I try send cloud message (Grow - Cloud Messaging) to this token nothing happend on phone. Even if app is running or not.

I don't know what next.

Uninstall and install I tried too.

Next wierd thing that Firebase still notice:

Run your app to verify installation
Checking if the app has communicated with our servers. You may need to uninstall and reinstall your app.

Thanks for your advices.

private void SetFirebaseCloudMessaging()
{
	Firebase.Core.App.Configure();
	Messaging.SharedInstance.Delegate = this;

	// Register your app for remote notifications.
	if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
	{
		// For iOS 10 display notification (sent via APNS)
		UNUserNotificationCenter.Current.Delegate = this;

		var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound;
		UNUserNotificationCenter.Current.RequestAuthorization(authOptions, (granted, error) => {
			Console.WriteLine(granted);
		});
	}
	else
	{
		// iOS 9 or before
		var allNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;
		var settings = UIUserNotificationSettings.GetSettingsForTypes(allNotificationTypes, null);
		UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
	}

	UIApplication.SharedApplication.RegisterForRemoteNotifications();
}

[Export("messaging:didReceiveRegistrationToken:")]
public void DidReceiveRegistrationToken(Messaging messaging, string fcmToken)
{
	Console.WriteLine($"DEBUG: Firebase registration token: {fcmToken}");
}
@lypefm
Copy link

lypefm commented Jun 16, 2020

I have same problem... notification working in foreground, but not working in background...

I enabled remote notification and fetch in the background at info.plist

i'm sending json from the notification with "content-available": 1 ...

I tried with

{
"to": "TokenID",
"notification": {
"title": "TITLE",
"body": "BODY"
},
"data": {
"title": "TITLE",
"body": "BODY",
"extraField1": "extra value 1",
"extraField2": "extra value 2"
},
"apns": {

  "headers": {
     "apns-topic": "<My-App>",
     "apns-push-type": "background",
     "apns-priority": 10
  }

}
}

I followed all these documentation

https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html

https://docs.microsoft.com/pt-br/xamarin/ios/app-fundamentals/backgrounding/ios-backgrounding-techniques/updating-an-application-in-the-background

I'm not sure what else I can do

@nmssalman
Copy link

same here. FMC receives, token can be seen, but notification not receiving. any idea?

@davidtabor90
Copy link
Author

Any advice?

@toanlcgift
Copy link

I think the problem is that apple has changed device token format:

https://stackoverflow.com/questions/8798725/get-device-token-for-push-notification
https://nshipster.com/apns-device-tokens/

The solution is updating FirebaseMessaging.framework to lastest version

@Kapusch
Copy link

Kapusch commented Dec 16, 2020

I have same problem... notification working in foreground, but not working in background...

I enabled remote notification and fetch in the background at info.plist

Thanks @lypefm , I have read about enabling "Remote notifications" in "background modes", but I was not aware about the need to enable "fetch in the background" too...

I've got more successful results thanks to following configuration :
image

@dasunmax89
Copy link

Hi All
same problem here.
but once I restarted the phone, suddenly it started working.
because this issue is still open, I think firebase still having this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants