首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Monodroid和pushsharp

Monodroid和pushsharp
EN

Stack Overflow用户
提问于 2012-09-20 16:20:49
回答 2查看 4K关注 0票数 2

有没有人在他们的monodroid应用程序中使用push Sharp (https://github.com/Redth/PushSharp)实现了推送通知?

我想使用这个解决方案,但是我还不能运行测试。

有没有人能提供一个关于如何做到这一点的教程?

谢谢

EN

回答 2

Stack Overflow用户

发布于 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通知非常简单:

代码语言:javascript
复制
//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。

祝好运!

票数 8
EN

Stack Overflow用户

发布于 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开始。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12508675

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档