我想在应用程序关闭时收到推送通知时将通知保存在realm db上,当在前台或后台运行时它可以工作,但是在关闭时不起作用,我无法捕获任何异常。
public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
{
if (null != userInfo && userInfo.ContainsKey(new NSString("aps")))
{
NSDictionary aps = userInfo.ObjectForKey(new NSString("aps")) as NSDictionary;
string title = "Agendarum Informa";
string notificationMessage = string.Empty;
if (aps.ContainsKey(new NSString("title")))
title = (aps[new NSString("title")] as NSString).ToString();
if (aps.ContainsKey(new NSString("alert")))
notificationMessage = (aps[new NSString("alert")] as NSString).ToString();
UIAlertView alert = new UIAlertView()
{
Title = title,
Message = notificationMessage
};
try
{
var now = DateTime.Now;
Realm _realm;
_realm = Realm.GetInstance();
_realm.Write(() =>
{
_realm.Add(new Models.RealmObjects.Notification()
{
Title = alert.Title,
Message = notificationMessage,
Date = now
});
});
}
catch (Exception ex)
{
UIAlertView alertEx = new UIAlertView()
{
Title = "ERRO",
Message = ex.Message
};
alertEx.AddButton("OK");
alertEx.Show();
}
alert.AddButton("OK");
alert.Show();
}
}
注意:在Android上运行正常...
有任何想法吗? 谢谢。