Xamarin.Forms - Toast(横幅) - 警报 - 在iOS和Android中的背景

时间:2016-05-01 17:19:29

标签: xamarin xamarin.ios xamarin.android xamarin.forms

我尝试在后台应用时显示祝酒词(横幅)通知。

我检查了后台提取和推送通知。当app在前台时,我也收到了推送通知。

但当我的应用程序在后台 - 我只看到如何更改我的徽章数量 - 但我没有看到通知

这是我的代码:

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

但我想了解如何在没有插件的情况下编写它。

谢谢。

1 个答案:

答案 0 :(得分:0)

好的 - 我解决了!

对于会遇到同样问题的开发人员:

我只是不将aps json中的ALERT对象发送到ios。