TheM00s3
TheM00s3

Reputation: 3711

setting user Device token after registration with Parse

From the push notification guide, Im noticing that parse recommends setting the device token from within the AppDelegate. Im interested in sending push notifications to certain users, and Im wondering if its possible to move the code for registering a device and their deviceToken within the login code which is found outside of the AppDelegate.

Upvotes: 2

Views: 630

Answers (2)

Ashwani Kumar
Ashwani Kumar

Reputation: 11

You can run this code after login/ signup in application

 PFInstallation *currentInstallation = [PFInstallation currentInstallation];

 [currentInstallation setDeviceTokenFromData:sharedInstance.DeviceToken];

 [currentInstallation setObject:[PFUser currentUser] forKey:@"user"];

 currentInstallation.channels = @[ @"channel" ];

 [currentInstallation saveInBackground];  

Upvotes: 1

Jacob
Jacob

Reputation: 2338

I think you should keep the deviceToken association in the delegate, but after the user logs in, grab the current installation and associate it with the user:

PFInstallation *current = [PFInstallation currentInstallation];
[current setObject:[PFUser currentUser] forKey:@"owner"];
[current saveInBackground];

Upvotes: 2

Related Questions