有没有人在他们的monodroid应用程序中使用push Sharp (https://github.com/Redth/PushSharp)实现了推送通知?
我想使用这个解决方案,但是我还不能运行测试。
有没有人能提供一个关于如何做到这一点的教程?
谢谢
发布于 2012-09-20 21:19:33
我是PushSharp的作者。
GCM运行得很好,并且很容易安装和运行!
要设置Google API的项目,可以遵循以下指南:https://github.com/Redth/PushSharp/wiki/How-to-Configure-&-Send-GCM-Google-Cloud-Messaging-Push-Notifications-using-PushSharp
正如@SpiritMachine提到的,您可以将客户端示例用于Mono for Android应用程序。最简单的方法可能是(如上所述)简单地获取项目,并根据自己的喜好进行调整。https://github.com/Redth/PushSharp/tree/master/Client.Samples/PushSharp.ClientSample.MonoForAndroid/PushSharp.ClientSample.MonoForAndroid.Gcm
最后,使用PushSharp从您的服务器发送GCM通知非常简单:
//Create a new instance of PushService
PushService push = new PushService();
//Configure and start Android GCM
//IMPORTANT: The SENDER_ID is your Google API Console App Project ID.
// Be sure to get the right Project ID from your Google APIs Console.
// It's not the named project ID that appears in the Overview,
// but instead the numeric project id in the url:
// eg: https://code.google.com/apis/console/?pli=1#project:785671162406:overview
// where 785671162406 is the project id, which is the SENDER_ID to use!
push.StartGoogleCloudMessagingPushService(
new GcmPushChannelSettings("785671162406", "AIzaSyC2PZNXQDVaUpZGmtsF_Vp8tHtIABVjazI", "com.pushsharp.test"));
//Fluent construction of an Android GCM Notification
//IMPORTANT: For Android you MUST use your own RegistrationId here
// that gets generated within your Android app itself!
push.QueueNotification(NotificationFactory.AndroidGcm()
.ForDeviceRegistrationId("<YOUR_REGISTRATION_ID_HERE>")
.WithCollapseKey("NONE")
.WithJson("{\"alert\":\"Alert Text!\",\"badge\":\"7\"}"));
//Stop the server if you have nothing else to send for a long time
// and tell it to process the remaining queue before exiting!
push.StopAllServices(true);当然,在NuGet上也可以使用PushSharp。
祝好运!
发布于 2012-09-20 18:50:16
GCM在Android上运行得非常好。
PushSharp服务器应用程序看起来提供了一些非常好的跨多个移动OS实现的功能和管理。
但是,如果您真的只是想用更少的功能访问GCM API,那么您可以相当快地上手并运行。
我使用this gem用Ruby语言编写了我自己的基本服务器。这是一个Sinatra应用程序,它只允许设备注册/注销,并提供HTTP URL来发布消息。我用了大约30LOC就完成了。不是开玩笑。它在Heroku上运行。
然后,我从PushSharp存储库中获取了MonoDroid客户端示例,将其自定义为使用我的应用程序接口进行注册/注销,否则对其进行了修改以满足我的需求。
不过,首先需要使用Google API创建一个项目,并为其打开GCM。您可以从该here开始。
https://stackoverflow.com/questions/12508675
复制相似问题