HMS Core Push Kit Sample Code (C#)
English | 中文
Contents
- Introduction
- Installation
- Configuration
- Environment Requirements
- Sample Code
- Technical Support
- License
Introduction
The sample code for C# encapsulates the server-side APIs of Push Kit, for your reference or direct use.
The following table describes folders of C# sample code.
Folder | Description |
---|---|
AGConnectAdmin | Class library where Push Kit server APIs are encapsulated. |
AGConnectAdmin.Examples | Class library usage examples. |
The following table describes main classes used in the sample code.
Class Name | Description |
---|---|
AppOptions | App-related configuration. |
AGConnectApp | App. |
AGConnectMessaging | Push Kit API calling methods. |
Message | Message body. |
Installation
- Decompress the sample code.
- Copy AGConnectAdmin to a proper position in your Visual Studio solution and reference the corresponding assembly in your project.
- Use the classes in AGConnectAdmin by referring to the sample code.
Configuration
The following table describes the parameters related to the AppOptions class.
Parameter | Description |
---|---|
ClientId | App ID, which is obtained from the app information. |
ClientSecret | App secret, which is obtained from the app information. |
LoginUri | URL for Huawei OAuth 2.0 to obtain a token. For details, please refer to OAuth 2.0-based Authentication. |
ApiBaseUri | Access address of Push Kit. For details, please refer to Downlink Message Sending. |
Environment Requirements
The demo projects need to be opened using Visual Studio 2017 or a later version. The following framework versions are supported:
- .NET Framework 4.5 or later
- .NET Standard 2.0 or later
Sample Code
AGConnectAdmin.Examples provides all sample code and corresponding functions.
-
Send a data message to an Android app. File path: AGConnectAdmin.Examples/Example.SendDataMessage.cs
-
Send a notification message to an Android app. File path: AGConnectAdmin.Examples/Example.SendAndroidMessage.cs
-
Send a message by topic. File path: AGConnectAdmin.Examples/Example.SendTopicMessage.cs
-
Send a message by condition. File path: AGConnectAdmin.Examples/Example.SendConditionMessage.cs
-
Send a message to a Huawei quick app. File path: AGConnectAdmin.Examples/Example.SendInstanceAppMessage.cs
-
Send a message by WebPush. File path: AGConnectAdmin.Examples/Example.SendWebpushMessage.cs
-
Send a message by APNs. File path: AGConnectAdmin.Examples/Example.SendApnsMessage.cs
-
Send a test message. File path: AGConnectAdmin.Examples/Example.SendTestMessage.cs
Technical Support
You can visit the Reddit community to obtain the latest information about HMS Core and communicate with other developers.
If you have any questions about the sample code, try the following:
- Visit Stack Overflow, submit your questions, and tag them with
huawei-mobile-services
. Huawei experts will answer your questions. - Visit the HMS Core section in the HUAWEI Developer Forum and communicate with other developers.
If you encounter any issues when using the sample code, submit your issues or submit a pull request.
License
The sample code is licensed under Apache License 2.0.