2017-06-29 8 views
0

最新のPushSharp(4.0.10)を使用して、iOSおよびAndroidデバイスに通知を送信しています。約9ヶ月前に私はこれをテストし、うまくいくように見えました。私は今日同じアプリケーションを試しましたが、デバイス(iPhone)は通知を受信しなくなりました。今日有効になっているはずのデバイストークンが更新されました。 apnsBroker.OnNotificationSucceededイベントは発生しますが、デバイスは通知を受け取ることはありません。 例外やその他のタイプのフィードバックはありません。PushSharpがiOSに通知を送信しましたが、受信していません

var config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Sandbox, "mycert.p12", "password"); 

     // Create a new broker 
     var apnsBroker = new ApnsServiceBroker(config); 

     // Wire up events 
     apnsBroker.OnNotificationFailed += (notification, aggregateEx) => 
     { 

      aggregateEx.Handle(ex => 
      { 

       // See what kind of exception it was to further diagnose 
       if (ex is ApnsNotificationException) 
       { 
        var notificationException = (ApnsNotificationException)ex; 

        // Deal with the failed notification 
        var apnsNotification = notificationException.Notification; 
        var statusCode = notificationException.ErrorStatusCode; 

        Console.WriteLine($"Apple Notification Failed: ID={apnsNotification.Identifier}, Code={statusCode}"); 

       } 
       else 
       { 
        // Inner exception might hold more useful information like an ApnsConnectionException   
        Console.WriteLine($"Apple Notification Failed for some unknown reason : {ex.InnerException}"); 
       } 

       // Mark it as handled 
       return true; 
      }); 
     }; 

     apnsBroker.OnNotificationSucceeded += (notification) => 
     { 
      Console.WriteLine("Apple Notification Sent!"); 
     }; 

     // Start the broker 
     apnsBroker.Start(); 

     var payload = new Dictionary<string, object>(); 
     var aps = new Dictionary<string, object>(); 
     aps.Add("alert", GetAlert()); 
     aps.Add("badge", 1); 
     aps.Add("sound", "chime.aiff"); 
     payload.Add("aps", aps);    
     payload.Add("data", "info"); 


     apnsBroker.QueueNotification(new ApnsNotification 
     { 
      DeviceToken = textBox1.Text, 
      Payload = JObject.Parse(Newtonsoft.Json.JsonConvert.SerializeObject(payload)) 
     }); 

     apnsBroker.Stop(); 
+0

APNから新しいトークンを取得したときに、トークンをサーバーに更新していますか?そうでなければ、トークンをキャッシュしていますか? – Subramanian

+0

私は常にトークンを更新して、期限切れでないことを確認します。 – jbassking10

+0

トークン受信のコードを通過できますか? – Subramanian

答えて

0

これは実際の動作例です。プッシュシャープをインストールし、このコードを実行してください。 有効なデバイストークン+証明書+証明書パスワードが必要であることを確認してください。

private void SendIOSPushNotification() 
{ 
    try 
    { 
     //Get Certificate 
     var appleCert = System.IO.File.ReadAllBytes(Server.MapPath("~/App_Data/Certificates_new.p12")); 

     // Configuration (NOTE: .pfx can also be used here) 
     var config = new ApnsConfiguration(ApnsConfiguration.ApnsServer## Heading ##Environment.Sandbox, appleCert, "YourCertificatePassword"); 

     // Create a new broker 
     var apnsBroker = new ApnsServiceBroker(config); 

     // Wire up events 
     apnsBroker.OnNotificationFailed += (notification, aggregateEx) => 
     { 
      aggregateEx.Handle(ex => 
      { 
       // See what kind of exception it was to further diagnose 
       if (ex is ApnsNotificationException) 
       { 
        var notificationException = (ApnsNotificationException)ex; 

        // Deal with the failed notification 
        var apnsNotification = notificationException.Notification; 
        var statusCode = notificationException.ErrorStatusCode; 

        Console.WriteLine($"Apple Notification Failed: ID={apnsNotification.Identifier}, Code={statusCode}"); 
       } 
       else 
       { 
        // Inner exception might hold more useful information like an ApnsConnectionException   
        Console.WriteLine($"Apple Notification Failed for some unknown reason : {ex.InnerException}"); 
       } 
       // Mark it as handled 
       return true; 
      }); 
     }; 

     apnsBroker.OnNotificationSucceeded += (notification) => 
     { 
      Console.WriteLine("Apple Notification Sent!"); 
     }; 

     var fbs = new FeedbackService(config); 
     fbs.FeedbackReceived += (string deviceToken, DateTime timestamp) => 
     { 
      lblResult.Text = deviceToken +" Expired"; 
      // Remove the deviceToken from your database 
      // timestamp is the time the token was reported as expired 
     }; 

     // Start Proccess 
     apnsBroker.Start(); 

     //Device Token 
     //string _deviceToken = "8b5f6b908ae3d84a3a9778b1f5f40cc73b33fe2 ? 5431e41702cee6e90c599f1e3"; 
     string[] deviceTokens = "8b5f6b908ae3d84a3a9778b1f5f40cc73b33fe25431e41702cee6e90c599f1e3,0592798256a0d2f9e00ea366d5bd3595789fa0f551431f1d707cab76d933c25c".Split(','); 

     foreach (string _deviceToken in deviceTokens) 
     { 
      apnsBroker.QueueNotification(new ApnsNotification 
      { 
       DeviceToken = _deviceToken, 
       Payload = JObject.Parse(("{\"aps\":{\"badge\":1,\"sound\":\"oven.caf\",\"category\":\"NEW_MESSAGE_CATEGORY\",\"alert\":\"" + (txtMessage.Text.Trim() + "\"}}"))) 
      }); 
     } 

     apnsBroker.Stop(); 
     //lblResult.Text = "Messages sent"; 
    } 
    catch (Exception) 
    { 
     throw; 
    } 
} 
関連する問題