2014-08-29 5 views
2

내 앱에서 푸시 알림을 통해 응답을 설정하고 싶습니다.Parse.com 푸시 알림에 응답

사용자 A는 사용자 B에게 메시지를 보냅니다.

사용자 B는 푸시를 통해 새 페이지로 앱을 엽니 다.

사용자 B는 사용자 A에게 응답 (푸시)을 보냅니다.

지금은 페이지를 열어 볼 수 있지만 필요한 데이터를 가져 오는 방법을 모르겠습니다.

여기에 내가 처음 푸시에서 구문 분석에서 무엇을 얻을 :

이 경우
userInfo: { 
    aps =  { 
     alert = "demo says HELLO WORLD"; 
    }; 

는, 데모 최초의 푸시를 보낸 사용자의 사용자 이름입니다. 나는 그것을 얻고 싶다, 그래서 사용자 B를위한 앱은 누구에게 답장을 보낼지 안다. 당신은 AppDelegate에에서이 문제를 처리해야합니다

PFPush *push = [[PFPush alloc] init]; 
    [push setQuery:pushQuery]; 
    [push setMessage:[NSString stringWithFormat:@"%@ says HELLO WORLD", [PFUser currentUser].username]]; 
    [push sendPushInBackground]; 

답변

2

:

여기 내 밀어 코드입니다. 푸시 알림으로부터 데이터를 수신하는 두 가지 방법이 있습니다. 아래

//Receive Push Notification when the app is active in foreground or background 
- (void)application:(UIApplication *)application 
      didReceiveRemoteNotification:(NSDictionary *)userInfo { 

    if(userInfo){ 
    //TODO: Handle the userInfo here 
    } 
} 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    //Get the push notification when app is not open 
    NSDictionary *remoteNotif = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey]; 

    if(remoteNotif){ 
     [self handleRemoteNotification:application userInfo:remoteNotif]; 
    } 

    return YES; 
} 

-(void)handleRemoteNotification:(UIApplication*)application userInfo:(NSDictionary*)userInfo{ 

    if(userInfo){ 
     //TODO: Handle the userInfo here 
    } 
} 

업데이트 답 : -이 경우

, 난 당신이 setData 대신 setMessage 경우를 사용한다고 생각합니다.

NSString * message =[NSString stringWithFormat:@"%@ says HELLO WORLD", [PFUser currentUser].username]; 
NSString * userID = @"userid"; //TODO: set Your userID here 

NSMutableDictionary * dataDict = [[NSMutableDictionary alloc]init]; 
[dataDict setObject:message forKey:@"message"]; 
[dataDict setObject:userID forKey:@"userID"]; 

PFPush *push = [[PFPush alloc] init]; 
[push setQuery:pushQuery]; 
[push setData:dataDict]; 
[push sendPushInBackground]; 
+0

오른쪽. 나는 그것을 설정했지만 위의 내용은 userInfo에서 얻은 전부입니다. 푸시를 보낸 사용자의 objectId를 얻으려면 어떻게해야합니까? –

+0

위의 업데이트를 참조하십시오. – Ricky

0

알림 페이로드에는 수신 응용 프로그램에 추가 데이터를 제공하기 위해 사전 항목이 포함될 수 있습니다. 이 내용은 Apple Local and Push Notification Programming Guide에 설명되어 있습니다. 당신이 구문 분석에서 푸시 메시지를 생성 할 때 귀하의 페이로드의 모습 있도록

, 당신은 보내는 사용자의 ObjectId가를 추가 할 수 있습니다이

userInfo: { 
    aps =  { 
     alert = "demo says HELLO WORLD"; 
    }, 
    sendingUserObject:142Xyd23 
}; 

클라우드 코드는 다음과 같이 될 것이다 -

- 앱에서 알림을받을 때
var pushMsg=user.get("username")+" says HELLO WORLD"; 
var pushData={alert: pushMsg, sendingUserObject: user.id}; 
var pushMap= {}; 
pushMap["data"]=pushData; 
var deviceQuery=new Parse.Query("installations"); 
deviceQuery.equalTo("currentUser",destination); 
deviceQuery.exists("deviceToken"); 
pushMap["where"]=deviceQuery; 
Parse.Push.send(pushMap); 

그런 다음 당신은 userInfo 사전에서 전송 오브젝트 ID를 검색 할 수 있습니다3210

관련 문제