【发布时间】:2020-01-27 00:10:03
【问题描述】:
我正在开发一个聊天应用程序,我使用Firebase 进行推送通知。
在Background 和Foreground 中,方法DidReceiveRemoteNotification() 运行良好。
但是当应用程序在Foreground 中时,我不想显示Firebase notification,因为它会惹恼用户。我只想在应用程序收到Firebase notification 并且不显示Firebase notification 时处理该事件。
我尝试在 Firebase 的配置上删除 2 个参数 alert-title 和 alert-body:
第一:http://{url}/demo?device-token={token}&alert-title={title}&alert-body={body}
稍后:http://{url}/demo?device-token={token}
更改Firebase 配置后,应用程序关闭时我无法推送Firebase notification。
所以,我必须使用First 配置。
=> Foreground 中的应用程序在Xamarin iOS 上时如何不显示Firebase notification?
这是我的代码:
public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
{
try
{
// App in Foreground
if (!_isInBackground)
{
// Foreground
if (userInfo?.ContainsKey(new NSString("payload")) == true)
{
// TODO: handle Foreground
return;
}
}
// App in Background
// Checking push notification message
if (userInfo?.ContainsKey(new NSString("payload")) == true)
{
var payload = userInfo[new NSString("payload")]?.ToString();
if (!string.IsNullOrEmpty(payload))
{
// TODO: handle Background
}
// Push notification message
PushNotificationManager.DidReceiveMessage(userInfo);
// Inform system of fetch results
completionHandler(UIBackgroundFetchResult.NewData);
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
请帮帮我!
【问题讨论】:
-
您好,能否在 Xamrain.ios 中显示
AppDelegate.cs的代码,这可以从那里实现。
标签: xamarin xamarin.forms xamarin.ios