在MonoDroid中解析推送通知 [英] Parse Push Notfications in MonoDroid

查看:62
本文介绍了在MonoDroid中解析推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我在我的MonoDroid应用程序中使用Xamarin商店中的Parse组件.这样我就可以使用以下代码存储对象

So I'm using the Parse component from the Xamarin store in my MonoDroid app. So I was able to use the following code to store an object

ParseClient.Initialize ("appid", "windowskey");

var obj = new ParseObject("Note");
obj ["text"] = "Hello, world!  This is a Xamarin app using Parse!";
obj ["tags"] = new List<string> {"welcome", "xamarin", "parse"};
obj.SaveAsync ();

我的真正目标是能够进行推送通知.即使存储了上述对象,Parse仍未在设备中注册该设备以能够发送推送通知.我还有什么想念的.注意:我正在模拟器中执行此操作,但是如果我没有记错的话,它仍然可以正常工作.

My real goal is to be able to do push notifications. Even though the above object stored, Parse did not register the device in the installations to be able to send push notifications. What else am I missing. Note: I'm doing this in the emulator but if i'm not mistaken it still should work.

推荐答案

@ basit-zia,是的,我做到了!我必须从Java Parse SDK为推送库创建一个绑定.我相信我能够除去所有必要元素之外的所有库.我不记得我到底做了什么.

@basit-zia, yes I did! I had to create a binding for the push library from the Java Parse SDK. I believe I was able to strip away all the libraries except for the necessary elements. I can't remember exactly what I did though.

然后在Main Activity类中,将以下内容放入OnStart()方法中:

Then in the Main Activity class, I put the following into the OnStart() method:

            // check for a notification
            if (Intent != null)
                try {
                string jsonString = Intent.Extras.GetString("com.parse.Data");
                PushObject jsonObj = JsonConvert.DeserializeObject<PushObject>(jsonString);

                if (jsonObj.alert != null) {
                    Toast.MakeText (BaseContext, jsonObj.alert, ToastLength.Long).Show ();
                }

                } catch (Exception e) {
                    Console.WriteLine ("JSONException: " + e.Message);
                }

并将以下内容放入OnCreate()方法中:

And put the following into the OnCreate() method:

            Com.Parse.Parse.Initialize(this, "app id here"}, "client key here");
            PushService.SetDefaultPushCallback (this, this.Class);
            PushService.StartServiceIfRequired (this);
            ParseInstallation.CurrentInstallation.SaveInBackground ();

这篇关于在MonoDroid中解析推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆