2017-09-25 12 views
0

私はxamarinフォームアプリを使用して通知をサポートしています。私はAndroid受信機でアンドロイドでやっています。私のサービスはAPI RESTに依存しているので、60秒ごとにHTTPリクエストを実行し、データを取得して通知として表示したいのですが、私は何日も検索しましたが、私のアプローチには届きませんか? これは不可能な場合、私はナゲットなどをiosプロジェクトの "xamarin forms solution"のみで使うことができますか?ここでhttpリクエストでxamarin iosにローカル通知を作成

 content = new UNMutableNotificationContent(); 
     content.Title = "Notification Title"; 
     content.Subtitle = "Notification Subtitle"; 
     content.Body = "This is the message body of the notification."; 
     content.Badge = 1; 
     content.CategoryIdentifier = "message"; 

     var trigger = UNTimeIntervalNotificationTrigger.CreateTrigger(60, true); 


     var requestID = "sampleRequest"; 
     var request = UNNotificationRequest.FromIdentifier(requestID, content, trigger); 

     UNUserNotificationCenter.Current.AddNotificationRequest(request, (err) => 
     { 
      if (err != null) 
      { 
       // Do something with error... 
      } 
     }); 

答えて

0

は、iOS

var alertsAllowed = false; 
UNUserNotificationCenter.Current.GetNotificationSettings((settings) => 
{ 
    alertsAllowed = (settings.AlertSetting == UNNotificationSetting.Enabled); 
}); 

if (alertsAllowed) 
{ 
    var content = new UNMutableNotificationContent(); 
    content.Title = "Incident Recorder"; 
    content.Subtitle = "Not Synchronised"; 
    content.Body = "There are one or more new incidents that have not been synchronised to the server."; 

    var trigger = UNTimeIntervalNotificationTrigger.CreateTrigger(5, false); 

    var requestID = "sampleRequest"; 
    var request = UNNotificationRequest.FromIdentifier(requestID, content, trigger); 

    UNUserNotificationCenter.Current.AddNotificationRequest(request, (err) => 
    { 
     if (err != null) 
     { 
      Console.WriteLine(err.LocalizedFailureReason); 
     } 
    }); 
} 

CreateTriggerの最初のパラメータにローカル通知を生成するための私のコードで通知が生成されるどのくらい前です。私はあなたの中に60人いると気づきます。また、アプリがフォアグラウンドになっている場合は通知が表示されないことに注意してください。

+0

私はあなたのような60の後に自動的にサーバーからデータをインポートするために私のhttp要求を呼び出すことができますか? –

+0

60(または5)は、サーバーからデータをインポートする頻度とは関係ありません。通知の表示を遅らせておく時間です。場合によってはタイマーを使用して、共有(PCL)コードからサーバーを呼び出す必要があります。データを取得したら、プラットフォーム固有のコードを呼び出して通知をトリガーします。 –

+0

アンドロイド・プラットフォームには、タイマーなしでバックグラウンドでコードを実行するサービスがあります。もしかするとiosのようなものがあるのでしょうか?とにかく、私は2番目の質問を説明できないと思います。ミスタースティーブ –

関連する問題