Friday, August 7, 2015

Push Notifications to a Geographical Area

JAVA

ParseGeoPoint weberUniversity = new ParseGeoPoint();
weberUniversity.latitude = 41.192127;
weberUniversity.longitude = -111.944816;

// Find users near a given location
ParseQuery userQuery = ParseUser.getQuery();
userQuery.whereWithinMiles("location", stadiumLocation, 1.0)

// Find devices associated with these users
ParseQuery pushQuery = ParseInstallation.getQuery();
pushQuery.whereMatchesQuery("user", userQuery);

// Send push notification to query
ParsePush push = new ParsePush();
push.setQuery(pushQuery); // Set our Installation query
push.setMessage("Free hotdogs at the Parse concession stand!");
push.sendInBackground();

SWIFT

PFGeoPoint weberUniversity = new PFGeoPoint()
weberUniversity.latitude = 41.192127
weberUniversity.longitude = -111.944816

// Find users near a given location
let userQuery = PFUser.query()
userQuery.whereKey("location", nearGeoPoint: weberUniversity, withinMiles: 1)

// Find devices associated with these users
let pushQuery = PFInstallation.query()
pushQuery.whereKey("user", matchesQuery: userQuery)

// Send push notification to query
let push = PFPush()
push.setQuery(pushQuery) // Set our Installation query
push.setMessage("New contest starting soon! Stay tuned.")
push.sendPushInBackground()

1 comment: