2

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

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

任何人都可以提供有关如何执行此操作的教程吗?

谢谢

4

2 回答 2

8

我是 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-20T13:19:33.077 回答
1

GCM 绝对适用于 Android。

PushSharp 服务器应用程序看起来提供了一些非常好的功能和跨多个移动操作系统实现的管理。

但是,如果您真的只是想以更简单的功能访问 GCM API,您可以快速启动并运行。

我使用这个 gem在 Ruby 中编写了自己的基本服务器。这是一个 Sinatra 应用程序,只允许设备注册/取消注册,并提供 HTTP URL 来发布消息。我在大约 30 LOC 内完成了它。可不是闹着玩的。它在 Heroku 上运行。

然后,我从 PushSharp 存储库中获取了 MonoDroid 客户端示例,对其进行了自定义,以使用我的 API 注册/取消注册,并对其进行调整以满足我的需求。

首先,您需要使用 Google API 创建一个项目并为其打开 GCM。你可以从这里开始。

于 2012-09-20T10:50:16.137 回答