Reputation: 183
I am building an iOS & Android application for a contractor. Basically it's a client that should show a list of notifications from a server.
The contractor plan to give this app to multiple client companies of his. for each company he will ship a server (dedicated to that client), and the mobile app will be installed on ANY device, and for each client fleet the drivers will only have to enter the IP of the client server.
My question is - can I use Parse (or any other remote push aggregator) with a single app but have multiple servers send push notifications to devices (these will NOT be 'broadcast' pushes to all devices - they will be aimed to specific devices) ?
Upvotes: 0
Views: 204
Reputation: 11598
I'm not sure what the "server" in this case it, but Parse should be able to handle what you want.
I would create standard User
and Installation
classes in Parse, plus a custom class called "company" (or "client" or whatever). You can add whatever fields you like for this class, but it seems like the important one for you would be "IP Address".
You can associate an Installation
with a User
and a User
with a company
. The data structure would be like this:
Installation -> (Pointer)User
User -> (Pointer)company
company -> (String)ipAddress
Then, when you want to send a PUSH for a particular IP address, you could do the following:
company
that matches the "IP address".User
objects that have the result from #1 as their company
property.Installation
objects that have their User
object in the array returned by #2.Here's a way to do it in Objective-C:
- (void)sendPushMessage:(NSString *)message
toClientWithIpAddress:(NSString *)ipAddress {
PFQuery *companyQuery = [PFQuery queryWithClassName:@"company"];
[companyQuery whereKey:@"ipAddress" equalTo:ipAddress];
[companyQuery getFirstObjectInBackgroundWithBlock:^(PFObject *company, NSError *error) {
// Do real error handling
PFQuery *userQuery = [PFUser query];
[userQuery whereKey:@"company" equalTo:company];
[userQuery findObjectsInBackgroundWithBlock:^(NSArray *users, NSError *error) {
// Do real error handling
PFQuery *installationQuery = [PFInstallation query];
[installationQuery whereKey:@"user" containedIn:users];
PFPush *push = [PFPush push];
[push setQuery:installationQuery];
[push setMessage:message];
// You could also have a completion block for this, if desired
[push sendPushInBackground];
}
];
}
];
}
Caveat: Although I wrote the code in Objective-C, and although Parse allows Client PUSH, it's recommended that you do this from a Cloud Code function.
Upvotes: 1