【发布时间】:2016-05-01 17:19:29
【问题描述】:
我尝试在后台显示 toasts(banners) 通知。
我检查了后台获取和推送通知。当应用程序在前台时,我也收到了推送通知。
但是当我的应用在后台时 - 我只看到如何更改我的徽章计数 - 但我看不到通知
这是我的代码:
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init ();
LoadApplication (new App ());
if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) {
var pushSettings = UIUserNotificationSettings.GetSettingsForTypes (
UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound,
new NSSet ());
UIApplication.SharedApplication.RegisterUserNotificationSettings (pushSettings);
UIApplication.SharedApplication.RegisterForRemoteNotifications ();
} else {
UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound;
UIApplication.SharedApplication.RegisterForRemoteNotificationTypes (notificationTypes);
}
return base.FinishedLaunching (app, options);
}
和
public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
{
NSDictionary dic = userInfo.ObjectForKey(new NSString("aps")) as NSDictionary;
var test = (dic[new NSString("test")] as NSString).ToString();
var alert = new UIAlertView ("Test title", "This is message", null, "Ok", "Button");
alert.Clicked += (object sender, UIButtonEventArgs e) => {Console.WriteLine(e.ButtonIndex);};
alert.Show ();
}
所以我怎么说 - 在前台一切都很好,但在后台我只看到新的徽章数量。
我也找到了这个插件:
https://components.xamarin.com/view/alert-center
但我想了解如何在没有插件的情况下编写它。
谢谢。
【问题讨论】:
标签: xamarin xamarin.ios xamarin.android xamarin.forms