2016-03-18 107 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) 
      { 


      }