2016-06-15 6 views
-1

iOSでグループチャットアプリケーションを作成しています。クライアント側(iOS)ではsignalRフレームワークが統合されています。サーバー側では、私はASP.NetのsignalRフレームワークを統合しています。SignalRを使用してサーバーからクライアントにメッセージをプッシュする方法

私の疑問は、私はサーバーからiPhoneにチャットメッセージを送信したいと思っています。サーバー側では、ASP.Net SignalR Hubを作成しています。サーバーからクライアント(iPhone)にメッセージを送信する方法。

// in server side i am writing like this 

using System; 
using System.Collections.Generic;  
using System.Linq;  
using System.Web;  
using Microsoft.AspNet.SignalR;  
namespace ProjectName  
{  
    public class ChatHub : Hub  
  {  
   #region Data Members 

   public void Connect(string myData)  
   {  
    var id = Context.ConnectionId; 

    // send to caller  
      Clients.Caller.onConnected(myData); 

      // send to all except caller client  
      Clients.AllExcept(id).onNewUserConnected(myData));   
     } 
   
     public void SendMessageToAll(string myData)   
     {    
      // Broad cast message  
      Clients.All.messageReceived(myData);   
     } 
  
     public void SendPrivateMessage(string toUserId, string message)   
     {    
      string fromUserId = Context.ConnectionId; 
  
      if (toUserId!= null && fromUserId !=null)     
      {   
       // send to    
       Clients.Client(toUserId).sendPrivateMessage(fromUserId, message);  

       // send to caller user   
       Clients.Caller.sendPrivateMessage(toUserId,message);   
      }  
     } 

     public override Task OnDisconnected(bool stopCalled)   
     {     
      var id = Context.ConnectionId; 
       
      Clients.All.onUserDisconnected(id); 

      return base.OnReconnected();   
     } 

     public void SendMessageToGroup(string myData)   
     {    
      groupID = "1"; 
      
      Clients.Group(groupID).getMessages(myData);    
     } 
      
     #endregion 

    }  
} 
+0

あなたは明らかに十分な努力をしていませんMikeが述べたようにsignalrがどのように動作するかを理解するには、すでにクライアントにメッセージを送信している必要があります。シグナルハブからクライアント側のメッセージを処理するIOSのライブラリが必要です。 –

答えて

1

簡単です。実際にあなたはすでにそれをしました。

public Task SendMessage(string message) 
{ 
    Clients.AllExcept(Context.ConnectionId).MessageReceived(message); 
} 

今すぐあなたのクライアントのハブプロキシで「MessageRecieved」を聞く必要があります。

そして、アプリがバックグラウンドにしてSignalRがまだ接続されている場合されている場合(つまり、大きなIFだ)あなたは(iOSデバイスでの)ローカル通知を送信することができます

UILocalNotification* localNotification = [[UILocalNotificationalloc] init]; 
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:60]; 
localNotification.alertBody = @"Your alert message"; 
localNotification.timeZone = [NSTimeZone defaultTimeZone]; 
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 

Read more about local notifications

+0

お返事ありがとうございます。しかし私の疑いは、私はサーバーからモバイルデバイスにメッセージを送信したい。ので、サーバーからモバイルデバイスにメッセージを送信する方法を教えてください。実際に私はすでにGoogleのsearch.in GoogleのコードをWebアプリケーションのために利用可能な多くのことをしている。モバイルアプリを送ろうとしています – satya

+0

あなたの質問は携帯端末にプッシュ通知を送信することだと思います。それが本当であれば、目的のためにSignalRを使用することはできません。あなたの応答に感謝して、PushSharpまたは同様のライブラリ –

+0

についていくつかの調査を行います。私のiOS開発者はiosでチャットアプリケーションを実装しています。だから私はasp.net.my疑問を使ってサーバーを維持しているのですが、私はchatResponderを使ってチャットメッセージを送信したいと思っています。 – satya

関連する問題