我正在使用Xamarin Forms,并使用Azure实施了推送通知。应用程序在前景中触发了DidReceiveRemoteNotification
方法。但是在后台模式下不会调用它。我在这种方法中存储“通知接收计数”,并且没有增加。我在设备上使用iOS版本11.4。我该如何解决?我在DidReceivedRemoteNotification
方法中调用下面的方法。
void ProcessNotification(NSDictionary options, bool fromFinishedLaunching)
{
if (null != options && options.ContainsKey(new NSString("aps")))
{
NSDictionary aps = options.ObjectForKey(new NSString("aps")) as NSDictionary;
string alert = string.Empty;
string type = string.Empty;
if (aps.ContainsKey(new NSString("alert")))
alert = (aps[new NSString("alert")] as NSString).ToString();
if (aps.ContainsKey(new NSString("type")))
type = (aps[new NSString("type")] as NSString).ToString();
if (type.ToLower() == "menu")
{
SettingClass.MenuNotification = true;
SettingClass.MenuNotificationCount += 1;
MenuCount += 1;
NSUserDefaults.StandardUserDefaults.SetString(MenuCount.ToString(), "MenuNotification");
}
if (type.ToLower() == "promo" || type.ToLower() == "promotion")
{
SettingClass.PromoNotification = true;
SettingClass.PromoNotificationCount += 1;
PromoCount += 1;
NSUserDefaults.StandardUserDefaults.SetString(PromoCount.ToString(), "PromoNotification");
}
if (!fromFinishedLaunching)
{
//Manually show an alert
if (!string.IsNullOrEmpty(alert))
{
MessagingCenter.Send("UpdateTabs", "NotificationCount");
UIAlertView avAlert = new UIAlertView(type, alert, null, "OK", null);
avAlert.Show();
}
}
}
}