{"id":13469823,"url":"https://github.com/Redth/PushSharp","last_synced_at":"2025-03-26T09:31:19.666Z","repository":{"id":3540409,"uuid":"4600400","full_name":"Redth/PushSharp","owner":"Redth","description":"A server-side library for sending Push Notifications to iOS (iPhone/iPad APNS), Android (C2DM and GCM - Google Cloud Message), Windows Phone, Windows 8, Amazon, Blackberry, and (soon) FirefoxOS devices!","archived":false,"fork":false,"pushed_at":"2023-06-19T01:46:42.000Z","size":10621,"stargazers_count":4382,"open_issues_count":211,"forks_count":1526,"subscribers_count":465,"default_branch":"master","last_synced_at":"2024-10-29T15:33:58.565Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"hitherejoe/MVVM_Hacker_News","license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Redth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2012-06-08T17:52:47.000Z","updated_at":"2024-10-26T10:00:57.000Z","dependencies_parsed_at":"2023-02-19T18:01:37.300Z","dependency_job_id":null,"html_url":"https://github.com/Redth/PushSharp","commit_stats":{"total_commits":480,"total_committers":43,"mean_commits":"11.162790697674419","dds":"0.13541666666666663","last_synced_commit":"f68bb1e0309d8d5cf4fde73fab87e6afc6072e7b"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Redth%2FPushSharp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Redth%2FPushSharp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Redth%2FPushSharp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Redth%2FPushSharp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Redth","download_url":"https://codeload.github.com/Redth/PushSharp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222131034,"owners_count":16936304,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T16:00:17.184Z","updated_at":"2024-10-29T23:31:24.303Z","avatar_url":"https://github.com/Redth.png","language":"C#","readme":"PushSharp v4.0\n==============\n\nPushSharp is a server-side library for sending Push Notifications to iOS/OSX (APNS), Android/Chrome (GCM/FCM), Windows/Windows Phone, Amazon (ADM) and Blackberry devices!\n\nPushSharp 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.\n\nPushSharp will now follow [semver](http://semver.org/) versioning, so major version numbers will go up as there are any breaking api changes. \n\n[![Join the chat at https://gitter.im/Redth/PushSharp](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Redth/PushSharp?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\n[![AppVeyor CI Status](https://ci.appveyor.com/api/projects/status/github/Redth/PushSharp?branch=master\u0026svg=true)](https://ci.appveyor.com/project/Redth/pushsharp)\n\n[![NuGet Version](https://badge.fury.io/nu/PushSharp.svg)](https://badge.fury.io/nu/PushSharp)\n\n - Read more on my blog http://redth.codes/pushsharp-3-0-the-push-awakens/\n - Join the [Gitter.im channel](https://gitter.im/Redth/PushSharp) with questions/feedback\n\n---\n\n## Sample Usage\n\nThe 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.\n\n### APNS Sample Usage\nHere is an example of how you would send an APNS notification:\n\n```csharp\n// Configuration (NOTE: .pfx can also be used here)\nvar config = new ApnsConfiguration (ApnsConfiguration.ApnsServerEnvironment.Sandbox, \n    \"push-cert.p12\", \"push-cert-pwd\");\n\n// Create a new broker\nvar apnsBroker = new ApnsServiceBroker (config);\n    \n// Wire up events\napnsBroker.OnNotificationFailed += (notification, aggregateEx) =\u003e {\n\n\taggregateEx.Handle (ex =\u003e {\n\t\n\t\t// See what kind of exception it was to further diagnose\n\t\tif (ex is ApnsNotificationException notificationException) {\n\t\t\t\n\t\t\t// Deal with the failed notification\n\t\t\tvar apnsNotification = notificationException.Notification;\n\t\t\tvar statusCode = notificationException.ErrorStatusCode;\n\n\t\t\tConsole.WriteLine ($\"Apple Notification Failed: ID={apnsNotification.Identifier}, Code={statusCode}\");\n\t\n\t\t} else {\n\t\t\t// Inner exception might hold more useful information like an ApnsConnectionException\t\t\t\n\t\t\tConsole.WriteLine ($\"Apple Notification Failed for some unknown reason : {ex.InnerException}\");\n\t\t}\n\n\t\t// Mark it as handled\n\t\treturn true;\n\t});\n};\n\napnsBroker.OnNotificationSucceeded += (notification) =\u003e {\n\tConsole.WriteLine (\"Apple Notification Sent!\");\n};\n\n// Start the broker\napnsBroker.Start ();\n\nforeach (var deviceToken in MY_DEVICE_TOKENS) {\n\t// Queue a notification to send\n\tapnsBroker.QueueNotification (new ApnsNotification {\n\t\tDeviceToken = deviceToken,\n\t\tPayload = JObject.Parse (\"{\\\"aps\\\":{\\\"badge\\\":7}}\")\n\t});\n}\n   \n// Stop the broker, wait for it to finish   \n// This isn't done after every message, but after you're\n// done with the broker\napnsBroker.Stop ();\n```\n\n#### Apple Notification Payload\n\nMore 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).\n\n\n#### Apple APNS Feedback Service\n\nFor 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:\n\n```csharp\nvar config = new ApnsConfiguration (\n    ApnsConfiguration.ApnsServerEnvironment.Sandbox, \n    Settings.Instance.ApnsCertificateFile, \n    Settings.Instance.ApnsCertificatePassword);\n\nvar fbs = new FeedbackService (config);\nfbs.FeedbackReceived += (string deviceToken, DateTime timestamp) =\u003e {\n    // Remove the deviceToken from your database\n    // timestamp is the time the token was reported as expired\n};\nfbs.Check ();\n```\n\n\n### GCM/FCM Sample Usage\n\nHere is how you would send a GCM/FCM Notification:\n\n```csharp\n// Configuration GCM (use this section for GCM)\nvar config = new GcmConfiguration (\"GCM-SENDER-ID\", \"AUTH-TOKEN\", null);\nvar provider = \"GCM\";\n\n// Configuration FCM (use this section for FCM)\n// var config = new GcmConfiguration(\"APIKEY\");\n// config.GcmUrl = \"https://fcm.googleapis.com/fcm/send\";\n// var provider = \"FCM\";\n\n// Create a new broker\nvar gcmBroker = new GcmServiceBroker (config);\n    \n// Wire up events\ngcmBroker.OnNotificationFailed += (notification, aggregateEx) =\u003e {\n\n\taggregateEx.Handle (ex =\u003e {\n\t\n\t\t// See what kind of exception it was to further diagnose\n\t\tif (ex is GcmNotificationException notificationException) {\n\t\t\t\n\t\t\t// Deal with the failed notification\n\t\t\tvar gcmNotification = notificationException.Notification;\n\t\t\tvar description = notificationException.Description;\n\n\t\t\tConsole.WriteLine ($\"{provider} Notification Failed: ID={gcmNotification.MessageId}, Desc={description}\");\n\t\t} else if (ex is GcmMulticastResultException multicastException) {\n\n\t\t\tforeach (var succeededNotification in multicastException.Succeeded) {\n\t\t\t\tConsole.WriteLine ($\"{provider} Notification Succeeded: ID={succeededNotification.MessageId}\");\n\t\t\t}\n\n\t\t\tforeach (var failedKvp in multicastException.Failed) {\n\t\t\t\tvar n = failedKvp.Key;\n\t\t\t\tvar e = failedKvp.Value;\n\n\t\t\t\tConsole.WriteLine ($\"{provider} Notification Failed: ID={n.MessageId}, Desc={e.Description}\");\n\t\t\t}\n\n\t\t} else if (ex is DeviceSubscriptionExpiredException expiredException) {\n\t\t\t\n\t\t\tvar oldId = expiredException.OldSubscriptionId;\n\t\t\tvar newId = expiredException.NewSubscriptionId;\n\n\t\t\tConsole.WriteLine ($\"Device RegistrationId Expired: {oldId}\");\n\n\t\t\tif (!string.IsNullOrWhiteSpace (newId)) {\n\t\t\t\t// If this value isn't null, our subscription changed and we should update our database\n\t\t\t\tConsole.WriteLine ($\"Device RegistrationId Changed To: {newId}\");\n\t\t\t}\n\t\t} else if (ex is RetryAfterException retryException) {\n\t\t\t\n\t\t\t// If you get rate limited, you should stop sending messages until after the RetryAfterUtc date\n\t\t\tConsole.WriteLine ($\"{provider} Rate Limited, don't send more until after {retryException.RetryAfterUtc}\");\n\t\t} else {\n\t\t\tConsole.WriteLine (\"{provider} Notification Failed for some unknown reason\");\n\t\t}\n\n\t\t// Mark it as handled\n\t\treturn true;\n\t});\n};\n\ngcmBroker.OnNotificationSucceeded += (notification) =\u003e {\n\tConsole.WriteLine (\"{provider} Notification Sent!\");\n};\n\n// Start the broker\ngcmBroker.Start ();\n\nforeach (var regId in MY_REGISTRATION_IDS) {\n\t// Queue a notification to send\n\tgcmBroker.QueueNotification (new GcmNotification {\n\t\tRegistrationIds = new List\u003cstring\u003e { \n\t\t\tregId\n\t\t},\n\t\tData = JObject.Parse (\"{ \\\"somekey\\\" : \\\"somevalue\\\" }\")\n\t});\n}\n   \n// Stop the broker, wait for it to finish   \n// This isn't done after every message, but after you're\n// done with the broker\ngcmBroker.Stop ();\n```\n\n#### Components of a GCM/FCM Notification\n\nGCM 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).\n\n\n### WNS Sample Usage\n\nHere's how to send WNS Notifications:\n\n```csharp\n// Configuration\nvar config = new WnsConfiguration (\"WNS_PACKAGE_NAME\", \"WNS_PACKAGE_SID\", \"WNS_CLIENT_SECRET\");\n\n// Create a new broker\nvar wnsBroker = new WnsServiceBroker (config);\n\n// Wire up events\nwnsBroker.OnNotificationFailed += (notification, aggregateEx) =\u003e {\n\n\taggregateEx.Handle (ex =\u003e {\n\t\n\t\t// See what kind of exception it was to further diagnose\n\t\tif (ex is WnsNotificationException notificationException) {\n\t\t\tConsole.WriteLine ($\"WNS Notification Failed: {notificationException.Message}\");\n\t\t} else {\n\t\t\tConsole.WriteLine (\"WNS Notification Failed for some (Unknown Reason)\");\n\t\t}\n\n\t\t// Mark it as handled\n\t\treturn true;\n\t});\n};\n\nwnsBroker.OnNotificationSucceeded += (notification) =\u003e {\n\tConsole.WriteLine (\"WNS Notification Sent!\");\n};\n\n// Start the broker\nwnsBroker.Start ();\n\nforeach (var uri in MY_DEVICE_CHANNEL_URIS) {\n\t// Queue a notification to send\n\twnsBroker.QueueNotification (new WnsToastNotification {\n\t\tChannelUri = uri,\n\t\tPayload = XElement.Parse (@\"\n\t\t\t\u003ctoast\u003e\n\t\t\t\t\u003cvisual\u003e\n\t\t\t\t\t\u003cbinding template=\"\"ToastText01\"\"\u003e\n\t\t\t\t\t\t\u003ctext id=\"\"1\"\"\u003eWNS_Send_Single\u003c/text\u003e\n\t\t\t\t\t\u003c/binding\u003e  \n\t\t\t\t\u003c/visual\u003e\n\t\t\t\u003c/toast\u003e\")\n\t});\n}\n\n// Stop the broker, wait for it to finish   \n// This isn't done after every message, but after you're\n// done with the broker\nwnsBroker.Stop ();\n```\n\n\n## How to Migrate from PushSharp 2.x to 3.x and higher\n\nPlease see this Wiki page for more information: https://github.com/Redth/PushSharp/wiki/Migrating-from-PushSharp-2.x-to-3.x\n\n\n## Roadmap\n\n - **APNS - Apple Push Notification Service** \n   - Finish HTTP/2 support (currently in another branch)\n - **GCM - Google Cloud Messaging** \n   - XMPP transport still under development\n - **Other**\n   - More NUnit tests to be written, with a test GCM Server, and eventually Test servers for other platforms\n   - New Xamarin Client samples (how to setup each platform as a push client) will be built and live in a separate repository to be less confusing\n   \n\nLicense\n-------\nCopyright 2012-2016 Jonathan Dick\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","funding_links":[],"categories":["C# #","C#","Tools","Push Notifications","推送通知"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRedth%2FPushSharp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRedth%2FPushSharp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRedth%2FPushSharp/lists"}