avivais / phonegap-parse-plugin

Phonegap 3.0.0 plugin for Parse.com push service
195 stars 315 forks source link

tips on How to store user pointer to Installation Object.. #48

Open gespim opened 9 years ago

gespim commented 9 years ago

I guess many folks using this plugin will face this issue. Because saving user obj to the installation is needed for targeted push notification. I finally made it work at 4:15am -:) for my ClassMade app (www.iClassMade.com), an app for college students to find girl/boy friends.

Here is how I made it work. I modified the getInstallationId function to let it take one parameter userid

and then in the CDVParsePlugin.m the getInstallationId function add the following code

//we just need to pass the userid from JS code to this function, and we can save it to the Installation @"rKGIJNHipB" NSString userid = [command.arguments objectAtIndex:0]; PFInstallation installation = [PFInstallation currentInstallation];

installation[@"user"] = [PFObject objectWithoutDataWithClassName:@"_User" objectId:userid]; [installation saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) { if (error != nil) { NSLog(@"ParsePushUserAssign save error."); } }];

then in my html js code, after user login just call

parsePlugin.getInstallationId(user.id,function(id) { console.log(id +" id");

                                  }, function(e) {
                                  console.log('error');
                                  });

cheers!

kkgelu commented 9 years ago

You could update the installation table with you user id yourself. Try this REST API: https://parse.com/docs/rest/guide#push-notifications-updating-installations

Or you can 'hack' the table from your JS code, var Installation = Parse.Object.extend("_Installation");

note the underscore.