Asp.net 推送通知

Asp.net Push notifications

我的 android 没有收到推送通知 app.I 尝试了很多供应商,但我仍然无法让它工作。 不,因为我的后端在 Asp.net 我想过使用 Azure 推送中心,但我不确定从哪里开始。而且我对推送通知也有一点经验。例如,我将如何发送像 "check that update" 这样的简单推送。

A​​mr,你可以使用 pushsharp (https://github.com/Redth/PushSharp),它是一个完整的库,可以将推送通知发送到 Android、iOS 等

这是配置和获取指南运行: https://github.com/Redth/PushSharp/wiki/How-to-Configure-&-Send-GCM-Google-Cloud-Messaging-Push-Notifications-using-PushSharp

我已经在几个项目中使用过它,效果很好。

希望对您有所帮助

尝试以下链接,因为它们提供来自 Android 的完全免费的无限制推送通知,而且实施起来非常简单:

https://onesignal.com/

https://pushover.net/

http://rzlts.com/

希望对您有所帮助。

@Amr Alaa:您可以使用 Azure 通知中心。它的实现非常简单。

您可以在 azure.by 中创建通知中心,转到“新建”>“应用服务”>“服务总线”>“通知中心”>“快速创建”>“提供中心名称”>“创建”

以后您可以在 asp.net application/api 中使用下面的代码(不管它是否处于 azure 状态。)

//you can create class and get instance of the hub in constructor

    private NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString("Your connectionstring", "your Notification hub name");

在您的 android 应用程序启动时使用设备令牌调用此方法。

public async string registerpushhandle(string handle = null)
    {

        try
        {


            string newRegistrationId = null;

            if (handle != null)
            {
                var registrations = await hub.GetRegistrationsByChannelAsync(handle, 500);

                foreach (RegistrationDescription registration in registrations)
                {
                    if (newRegistrationId == null)
                    {
                        newRegistrationId = registration.RegistrationId;
                    }
                    else
                    {
                        await hub.DeleteRegistrationAsync(registration);
                    }
                }
            }

            if (newRegistrationId == null) newRegistrationId = await hub.CreateRegistrationIdAsync();


        }
        catch (Exception ex)
        {


        }
        return newRegistrationId 
    }

获取注册 ID 后,通过传递您的注册 ID、平台和设备令牌调用此方法。

public async void registerpushid(string id, string platform, string handle)
        {


            try
            {

                RegistrationDescription registration = null;
                switch (platform.ToLower())
                {
                    case "mpns":
                        registration = new MpnsRegistrationDescription(handle);
                        break;
                    case "wns":
                        registration = new WindowsRegistrationDescription(handle);
                        break;
                    case "apns":
                        registration = new AppleRegistrationDescription(handle);
                        break;
                    case "gcm":
                        registration = new GcmRegistrationDescription(handle);
                        break;

                }

                registration.RegistrationId = id;



                registration.Tags = new HashSet<string>();
                registration.Tags.Add(handle);
                 registration.Tags.Add("yourcustometag");


                try
                {
                    await hub.CreateOrUpdateRegistrationAsync(registration);


                }
                catch (MessagingException e)
                {

                }


            }
            catch (Exception ex)
            {


            }