2016-03-18 104 views
-2

推送通知不会收到我的Android应用程序。我尝试了很多提供商,但我仍然无法让它工作。 没有,因为我的后端是在Asp.net我想使用Azure push hub,我不知道从哪里开始。并且我也有推送通知的一些经验。例如,我将如何发送像“检查更新”这样的简单推送。Asp.net推送通知

回答

0

@Amr Alaa:你可以去蔚蓝色的通知中心。它有非常简单的实现。

你可以创建azure.by要新建>应用服务>服务总线>的通知中心通知中心>快速创建>给轮毂名>创建

后者,你可以在你的asp.net应用程序使用波纹管代码在启动应用程序调用此方法divice令牌/ API(不要紧,它是天蓝色或没有。)

//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通过传递您的registrationid,plateform和device令牌调用此方法。

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) 
      { 


      }