PushSharp v4.0
==============
PushSharp is a server-side library for sending Push Notifications to iOS/OSX (APNS), Android/Chrome (GCM), Windows/Windows Phone, Amazon (ADM) and Blackberry devices!
PushSharp v3.0+ is a complete rewrite of the original library, aimed at taking advantage of things like async/await, HttpClient, and generally a better infrastructure using lessons learned from the old code.
PushSharp will now follow [semver](http://semver.org/) versioning, so major version numbers will go up as there are any breaking api changes.
[![Join the chat at https://gitter.im/Redth/PushSharp](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Redth/PushSharp?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![AppVeyor CI Status](https://ci.appveyor.com/api/projects/status/github/Redth/PushSharp?branch=master&svg=true)](https://ci.appveyor.com/project/Redth/pushsharp)
[![NuGet Version](https://badge.fury.io/nu/PushSharp.svg)](https://badge.fury.io/nu/PushSharp)
- Read more on my blog http://redth.codes/pushsharp-3-0-the-push-awakens/
- Join the [Gitter.im channel](https://gitter.im/Redth/PushSharp) with questions/feedback
---
## Sample Usage
The API in v3.x+ series is quite different from 2.x. The goal is to simplify things and focus on the core functionality of the library, leaving things like constructing valid payloads up to the developer.
### APNS Sample Usage
Here is an example of how you would send an APNS notification:
```csharp
// Configuration (NOTE: .pfx can also be used here)
var config = new ApnsConfiguration (ApnsConfiguration.ApnsServerEnvironment.Sandbox,
"push-cert.p12", "push-cert-pwd");
// Create a new broker
var apnsBroker = new ApnsServiceBroker (config);
// Wire up events
apnsBroker.OnNotificationFailed += (notification, aggregateEx) => {
aggregateEx.Handle (ex => {
// See what kind of exception it was to further diagnose
if (ex is ApnsNotificationException) {
var notificationException = (ApnsNotificationException)ex;
// Deal with the failed notification
var apnsNotification = notificationException.Notification;
var statusCode = notificationException.ErrorStatusCode;
Console.WriteLine ($"Apple Notification Failed: ID={apnsNotification.Identifier}, Code={statusCode}");
} else {
// Inner exception might hold more useful information like an ApnsConnectionException
Console.WriteLine ($"Apple Notification Failed for some unknown reason : {ex.InnerException}");
}
// Mark it as handled
return true;
});
};
apnsBroker.OnNotificationSucceeded += (notification) => {
Console.WriteLine ("Apple Notification Sent!");
};
// Start the broker
apnsBroker.Start ();
foreach (var deviceToken in MY_DEVICE_TOKENS) {
// Queue a notification to send
apnsBroker.QueueNotification (new ApnsNotification {
DeviceToken = deviceToken,
Payload = JObject.Parse ("{\"aps\":{\"badge\":7}}")
});
}
// Stop the broker, wait for it to finish
// This isn't done after every message, but after you're
// done with the broker
apnsBroker.Stop ();
```
#### Apple Notification Payload
More information about the payload sent in the ApnsNotification object can be found [here](https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/TheNotificationPayload.html).
#### Apple APNS Feedback Service
For APNS you will also need to occasionally check with the feedback service to see if there are any expired device tokens you should no longer send notifications to. Here's an example of how you would do that:
```csharp
var config = new ApnsConfiguration (
ApnsConfiguration.ApnsServerEnvironment.Sandbox,
Settings.Instance.ApnsCertificateFile,
Settings.Instance.ApnsCertificatePassword);
var fbs = new FeedbackService (config);
fbs.FeedbackReceived += (string deviceToken, DateTime timestamp) => {
// Remove the deviceToken from your database
// timestamp is the time the token was reported as expired
};
fbs.Check ();
```
### GCM Sample Usage
Here is how you would send a GCM Notification:
```csharp
// Configuration
var config = new GcmConfiguration ("GCM-SENDER-ID", "AUTH-TOKEN", null);
// Create a new broker
var gcmBroker = new GcmServiceBroker (config);
// Wire up events
gcmBroker.OnNotificationFailed += (notification, aggregateEx) => {
aggregateEx.Handle (ex => {
// See what kind of exception it was to further diagnose
if (ex is GcmNotificationException) {
var notificationException = (GcmNotificationException)ex;
// Deal with the failed notification
var gcmNotification = notificationException.Notification;
var description = notificationException.Description;
Console.WriteLine ($"GCM Notification Failed: ID={gcmNotification.MessageId}, Desc={description}");
} else if (ex is GcmMulticastResultException) {
var multicastException = (GcmMulticastResultException)ex;
foreach (var succeededNotification in multicastException.Succeeded) {
Console.WriteLine ($"GCM Notification Failed: ID={succeededNotification.MessageId}");
}
foreach (var failedKvp in multicastException.Failed) {
var n = failedKvp.Key;
var e = failedKvp.Value;
Console.WriteLine ($"GCM Notification Failed: ID={n.MessageId}, Desc={e.Description}");
}
} else if (ex is DeviceSubscriptionExpiredException) {
var expiredException = (DeviceSubscriptionExpiredException)ex;
var oldId = expiredException.OldSubscriptionId;
var newId = expiredException.NewSubscriptionId;
Console.WriteLine ($"Device RegistrationId Expired: {oldId}");
if (!string.IsNullOrWhitespace (newId)) {
// If this value isn't null, our subscription changed and we should update our database
Console.WriteLine ($"Device RegistrationId Changed To: {newId}");
}
} else if (ex is RetryAfterException) {
var retryException = (RetryAfterException)ex;
// If you get rate limited, you should stop sending messages until after the RetryAfterUtc date
Console.WriteLine ($"GCM Rate Limited, don't send more until after {retryException.RetryAfterUtc}");
} else {
Console.WriteLine ("GCM Notification Failed for some unknown reason");
}
// Mark it as handled
return true;
});
};
gcmBroker.OnNotificationSucceeded += (notification) => {
Console.WriteLine ("GCM Notification Sent!");
};
// Start the broker
gcmBroker.Start ();
foreach (var regId in MY_REGISTRATION_IDS) {
// Queue a notification to send
gcmBroker.QueueNotification (new GcmNotification {
RegistrationIds = new List<string> {
regId
},
Data = JObject.Parse ("{ \"somekey\" : \"somevalue\" }")
});
}
// Stop the broker, wait for it to finish
// This isn't done after every message, but after you're
// done with the broker
gcmBroker.Stop ();
```
#### Components of a GCM Notification
GCM notifications are much more customizable than Apple Push Notifications. More information about the messaging concepts and options can be found [here](https://developers.google.com/cloud-messaging/concept-options#components-of-a-message).
### WNS Sample Usage
Here's how to send WNS Notifications:
```csharp
// Configuration
var config = new WnsConfiguration ("WNS_PACKAGE_NAME", "WNS_PACKAGE_SID", "WNS_CLIENT_SECRET");
// Create a new broker
var wnsBroker = new WnsServiceBroker (config);
// Wire up events
wnsBroker.OnNotificationFailed += (notification, aggregateEx) => {
aggregateEx.Handle (ex => {
// See what kind of exception it was to further diagnose
if (ex is WnsNotificationException) {
var notificationException = (WnsNotificationException)ex;
Console.WriteLine ($"WNS Notification Failed: {notificationException.Message}");
} else {
Console.WriteLine ("WNS Notification Failed for some (Unknown Reason)");
}
// Mark it as handled
return true;
});
};
wnsBroker.OnNotificationSucceeded += (notification) => {
Console.WriteLine ("WNS Notification Sent!");
};
// Start th
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
PushSharp移动消息推送库 v4.0.10.zip (120个子文件)
packages.config 204B
packages.config 139B
packages.config 139B
packages.config 139B
packages.config 139B
ApnsConnection.cs 18KB
TestApnsServer.cs 12KB
GcmXmppConnection.cs 12KB
GcmServiceConnection.cs 9KB
WnsConnection.cs 9KB
ApnsConfiguration.cs 9KB
ServiceBroker.cs 7KB
GcmNotification.cs 7KB
ApnsNotification.cs 6KB
AdmConnection.cs 6KB
ApnsHttp2Configuration.cs 6KB
ApnsTests.cs 6KB
BlackberryNotification.cs 5KB
Enums.cs 5KB
ApnsHttp2Connection.cs 5KB
ApnsFeedbackService.cs 4KB
GcmXmppNotification.cs 4KB
Log.cs 4KB
WnsRealTests.cs 3KB
PushHttpClient.cs 3KB
BlackberryConnection.cs 3KB
Settings.cs 3KB
GcmXmppResponse.cs 3KB
ApnsHttp2Notification.cs 3KB
WnsTokenAccessManager.cs 2KB
GcmResponse.cs 2KB
GcmMessageResult.cs 2KB
BrokerTests.cs 2KB
Exceptions.cs 2KB
ApnsRealTest.cs 2KB
BlackberryConfiguration.cs 2KB
BlackberryHttpClient.cs 2KB
GcmXmppConfiguration.cs 2KB
Exceptions.cs 2KB
FirefoxConnection.cs 2KB
ApnsServiceConnection.cs 2KB
TestServiceConnection.cs 2KB
GcmXmppService.cs 1KB
ApnsHttp2RealTests.cs 1KB
AdmNotification.cs 1KB
GcmRealTests.cs 1KB
WnsNotification.cs 1KB
AdmRealTests.cs 1KB
ApnsHttp2ServiceConnection.cs 1KB
FirefoxNotification.cs 1KB
GcmXmppTests.cs 1KB
GcmConfiguration.cs 1KB
Exceptions.cs 1KB
AssemblyInfo.cs 1001B
AssemblyInfo.cs 998B
AssemblyInfo.cs 998B
AssemblyInfo.cs 997B
AssemblyInfo.cs 997B
AssemblyInfo.cs 996B
AssemblyInfo.cs 995B
WnsNotificationStatus.cs 959B
AdmConfiguration.cs 935B
Exceptions.cs 881B
GcmTests.cs 852B
ServiceBrokerConfiguration.cs 771B
Exceptions.cs 638B
Exceptions.cs 634B
IServiceBroker.cs 579B
WnsConfiguration.cs 556B
IServiceConnection.cs 528B
Exceptions.cs 420B
IServiceConnectionFactory.cs 211B
INotification.cs 172B
FirefoxConfiguration.cs 160B
NotificationBlockingCollection.cs 150B
PushSharp.Tests.csproj 3KB
PushSharp.Google.csproj 2KB
PushSharp.Windows.csproj 2KB
PushSharp.Apple.csproj 2KB
PushSharp.Blackberry.csproj 2KB
PushSharp.Amazon.csproj 2KB
PushSharp.Core.csproj 2KB
PushSharp.Firefox.csproj 2KB
.gitattributes 483B
.gitignore 382B
.gitmodules 78B
说明.htm 4KB
settings.sample.json 296B
README.md 10KB
CONTRIBUTING.md 841B
LICENSE.md 580B
ISSUE_TEMPLATE.md 176B
PushSharp.nuspec 3KB
apns-com.pushsharp.sample.p12 3KB
PushSharp.Apns.Production.p12 3KB
PushSharp.Apns.Sandbox.p12 3KB
apns-03.png 414KB
apns-11.png 377KB
apns-10.png 367KB
apns-05.png 302KB
共 120 条
- 1
- 2
资源评论
小小姑娘很大
- 粉丝: 4070
- 资源: 2317
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于matlab 概率神经网络的分类预测-基于PNN的变压器故障诊断源代码+详细教程
- IMG_2779.PNG
- 基于matlab Elman神经网络的数据预测-电力负荷预测模型研究源代码+详细教程
- 架构师软考知识点整理2
- 基于matlab SOM神经网络的数据分类-柴油机故障诊断源代码+详细教程
- 2023.cpp
- 基于matlab 自组织竞争网络在模式分类中的应用-患者癌症发病预测源代码+详细教程
- 在线考试系统 JAVA+Spring+SpringMVC+MyBatis
- 毕业设计基于Python卷积神经网络CNN的图像分类系统源码+模型+说明文档+全部数据资料.zip
- matlab 基于SVM的手写字体识别源代码+详细教程
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功