2016-06-15 3 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

당신을 로컬 알림을 보낼 수 있습니다 (IF 그 큰의) 경우 Mike가 말했듯이 signalr의 작동 방식을 이해하려면 이미 클라이언트에 메시지를 보냈습니다. 신호기 허브에서 클라이언트 측 메시지를 처리하는 IOS 라이브러리가 필요합니다. –

답변

1

간단합니다. 사실 당신은 이미 그것을했습니다.

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

이제 클라이언트 허브 프록시에서 "MessageRecieved"를 청취해야합니다.

그리고

응용 프로그램이 백그라운드로하고 SignalR 여전히 연결하면 충분한 노력을하지 않은 명확하게 (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

답변 해 주셔서 감사합니다. 하지만 내 의심 나는 서버에서 모바일 장치로 메시지를 보내고 싶다. 그래서 plz 서버에서 모바일 장치로 메시지를 보내는 방법을 말해. 실제로 나는 이미 Google search.in 구글 코드를 웹 응용 프로그램에 사용할 수있는 많은 일을하고 있어요. 모바일 앱을 보내고 싶습니다 – satya

+0

휴대 기기에 푸시 알림을 보내는 것과 관련하여 궁금합니다. 그것이 사실이라면, 당신은 목적을 위해 SignalR을 사용할 수 없습니다. 귀하의 응답에 대해 PushSharp 또는 유사 라이브러리 –

+0

에 대해 조사해주십시오. 하지만 iOS에서 채팅 응용 프로그램을 구현하는 내 iOS 개발자 ... 그래서 iam asp.net.my 의심을 사용하여 서버를 유지하는 것은 chatRemote를 사용하여 iSMS에 채팅 메시지를 보내고 싶습니다. – satya

관련 문제