【发布时间】:2018-07-09 12:28:12
【问题描述】:
我正在使用 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();
}
}
}
}
【问题讨论】: