2014-09-01 2 views
2

나는 푸시 알림을 보내고 받기 위해 Parse을 사용했습니다. 나는 튜토리얼을 조금씩 따라 갔고 성공적으로 구현했다. 이제 사용자가 선택한 특정 마일 이내에 사용자에게 알림을 보내야합니다.구문 분석을 사용하여 특정 마일 내에서 푸시 알림 보내기

예 : 사용자가 을 선택한 경우 내 앱을 설치하고 현재 위치 (알림을 브로드 캐스트하는 사용자)로부터 100 마일 이내에있는 모든 사용자에게 알림을 보내야합니다.

나는 같은에 대한 구문 분석의 웹 사이트에 코드를 발견하지만 난 두 번째 쿼리 를 사용하는 경우 호출되지 않습니다 다음 코드 방법 didReceiveRemoteNotification에 주석 두 번째 쿼리를 사용하는 경우 내가 어떤 알림이 수신되지 않는 경우. 첫 번째 쿼리를 사용하는 경우에만 알림을 성공적으로받습니다.

푸시 알림 및 구문 분석에 더 익숙합니다. 어리석은 뭔가를 놓치고있어 내가 고칠 수 있다면 알려주지. 나는이 문제를 아주 오랫동안 돌았고 사람들이 도와 줘.

PFGeoPoint *myLoc = [PFGeoPoint geoPointWithLatitude:myLatitude longitude:myLongitude]; 

     PFQuery *userQuery = [PFUser query]; 
     [userQuery whereKey:@"location" 
       nearGeoPoint:myLoc 
       withinMiles:100]; 

     PFQuery *myQuery = [PFInstallation query]; 
     [myQuery whereKey:@"deviceType" equalTo:@"ios"]; 
     //[myQuery whereKey:@"user" matchesQuery:userQuery]; 


     NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys: 
           txt.text, @"alert", 
           @"1", @"badge", 
           @"sound.caf", @"sound", 
           nil]; 


     PFPush *push = [[PFPush alloc] init]; 
     [push setQuery:myQuery]; 
     [push setData:data]; 
     [push sendPushInBackground]; 
+0

'위치'알림을 보낼 위치에서 코드 다음

[PFGeoPoint geoPointForCurrentLocationInBackground:^(PFGeoPoint *geoPoint, NSError *error) { if (!error) { NSLog(@"User is currently at %f, %f", geoPoint.latitude, geoPoint.longitude); PFInstallation *currentInstallation = [PFInstallation currentInstallation]; [currentInstallation setDeviceTokenFromData:deviceToken]; currentInstallation[@"location"] = geoPoint; [currentInstallation saveInBackground]; } else { NSLog(@"%@", error); return; } }]; 

넣어 당신의 Appdelgate's 방법 didRegisterForRemoteNotificationsWithDeviceToken 넣어 다음 코드에서

우선 지리적 포인트가 맞습니까? 그리고 설치 테이블에 '사용자'열이 있습니까? – Jacob

+0

위치 열에서 위도 또는 경도를 입력하면 해당 값을 공유합니다. – Maul

+0

@ 제이콥 : 백엔드에 테이블이없는 것 같습니다. 내가 본 쿼리 만있는 그대로입니다. – iCodeAtApple

답변

5

나는이 프로젝트에서 다음과 같은 코드와 단계가 당신에게 도움이되기를 바랍니다. A는 당신이 사용자 테이블에서 다른 사람에게

PFInstallation *installation = [PFInstallation currentInstallation]; 
    NSLog(@"%@",installation); 
    [PFGeoPoint geoPointForCurrentLocationInBackground:^(PFGeoPoint *geoPoint, NSError *error) 
    { 
     if (!error) 
     { 
      PFQuery *userQuery = [PFInstallation query]; 
      [userQuery whereKey:@"location" 
        nearGeoPoint:geoPoint 
        withinMiles:100.00]; 
      NSString *str_CurrentDeviceToken = [NSString stringWithFormat:@"%@",[installation objectForKey:@"deviceToken"]]; 
      [userQuery whereKey:@"deviceToken" notEqualTo:str_CurrentDeviceToken]; 
      NSLog(@"%@",userQuery); 


      NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys: 
            @"Hello", @"alert", 
            @"1", @"badge", 
            @"", @"sound", 
            nil]; 


      PFPush *push = [[PFPush alloc] init]; 
      [push setQuery:userQuery]; 
      [push setData:data]; 
      [push sendPushInBackground]; 
     } 
     else 
     { 
      NSLog(@"%@", error); 
      return; 
     } 
    }]; 
+0

Worked Perfectly !! 고마워요 :) – iCodeAtApple

+0

당신을 환영합니다 !!!!! – Maul

관련 문제