send message to loggded In user using parse - ios

I have created a database on parse.com
I want to send push notification to logged in user
I have created "Installation" class.
in that class I have added two devices with device token.
and after logged in app I have added field "owner" with loginId.
After that I am trying to send push notification to logged in used from my device but my code not working
here is code of send button
- (IBAction)WRMethodBtnSendMsg:(id)sender {
// Send a notification to all devices subscribed to the "Giants" channel.
PFQuery *tmpQuery = [PFInstallation query];
[tmpQuery whereKey:#"owner" containsString:[self.sdPFObject objectId]];
PFPush *push = [[PFPush alloc] init];
[push setQuery:tmpQuery];
[push setMessage:self.wrTxtMsg.text];
[push sendPushInBackground];
}
but push notification doesn't send
Appreciate for help

I'd use channels. Have every user subscribe to a "user channel", something along the line of user_*user_id_here*. Then, when you want to send a push notification to the user with ID 123456, simply send it to the user_123456 channel.

Related

iOS: Firebase invite through email not working

I am trying to send the invitation through emails using Firebase. When i select the user and tap on send, i got an alert view saying invitation has been sent successfully. But i am not getting the email to the invitee.
Here is my code for sending the invite.
// Invite friends
id<FIRInviteBuilder> inviteDialog = [FIRInvites inviteDialog];
[inviteDialog setInviteDelegate:self];
FIRInvitesTargetApplication *targetApplication = [[FIRInvitesTargetApplication alloc] init];
targetApplication.androidClientID = #"Android ID";
[inviteDialog setOtherPlatformsTargetApplication:targetApplication];
NSString *message =
[NSString stringWithFormat:#"Try this out!\n -%#",
#"Ankur"];
[inviteDialog setMessage:message];
[inviteDialog setTitle:#"Invites Friends"];
[inviteDialog setDeepLink:#"Deep_Link"];
[inviteDialog setCallToActionText:#"Install!"];
[inviteDialog open];
At the same time, i am getting the invitation if i send it through phone number.
Any help would be appreciated. Thanks!
You need to add your team ID in the firebase console, it is also required that you add an App Store id (it's ok to fake one for testing)
I was having this issue because i have not mentioned the app store id in firebase console. After saving the AppStore ID, the issue got resolved.

Parse iOS - Send push notification at specific time

A part of my app currently lets a user schedule appointments using a UIDatePicker. They press a button and my backend does some work with the date to store the appointment data, then I send a push using the following code:
NSString *objectID = [NSString stringWithFormat:#"user_%lu", (unsigned long)self.salespersonObject.userID];
PFPush *push = [PFPush new];
[push setChannel:[NSString stringWithFormat:#"%#",objectID]];
NSString *message1 = [NSString stringWithFormat:#"%# sent you an appointment request. Visit your profile in the app to confirm", self.currentUser.fullName];
NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys:
message1, #"alert",
#"Increment", #"badge",#"default",#"sound",
nil];
[push setData: data];
[push sendPushInBackground];
What I'm wondering ... is there any way using the Parse iOS SDK to set a specific time for a push to be delivered? I'd like to also in this method add a push to be sent 1 hour prior to the UIDatePicker date that says something like "Reminder your appointment with x is in 1 hour"
Thanks in advance!
From Parse Doc :
Sending scheduled push notifications is not currently supported by the
iOS or OS X SDKs. Take a look at the REST API, JavaScript SDK or the
Parse.com push console.
The best thing to do IMO is to use Cloud Code, so you can make a trigger (afterSave, afterDelete) or a function that you call from your iOS App.
Since CloudCode use the Javascript SDK you can make something like that:
var tomorrowDate = new Date(...);
var query = new Parse.Query(Parse.Installation);
query.equalTo('user_id', 'user_123');
Parse.Push.send({
where: query,
data: {
alert: "You previously created a reminder for the game today"
},
push_time: tomorrowDate
}, {
success: function() {
// Push was successful
},
error: function(error) {
// Handle error
}
});
Parse Push notification scheduling Guide
You can use parse Background jobs to schedule the push notification.
Here is the link for documentation
There really isn't a whole lot you can do with the iPhone SDK and a closed app.
I would suggest that you assign the push to a channel, sending notifications is often done from the Parse.com push console, the REST API or from Cloud Code, you can also assign background jobs through this medium.
But if you want to stick to objective C as you don't mention any other languages; You can send Local Push Notifications natively but not through the PARSE SDK.

How to block specific user push notification in parse iOS app?

I am working on a iOS chatting app by use parse as backend service. If user blocks another user, how to prevent the push notifications? Is that possible to filter this push notification in parse side?
Really appreciate in advance.
There are several different ways to block a push notification from being sent to a user that blocked the sender. It really depends on how you handle the blocking of the user.
You could, for instance, add a blockedUsernames array to each user. If you did this, you could block the push notification from being sent in the first place, by cross checking this blocked users array against the users it is being sent to.
// CHECK FOR BLOCKED USERS
PFUser *currentUser = [PFUser currentUser]; // user sending push
PFUser *sendPushToUser = //user receiving the push
// Get array of blocked users
NSMutableArray *blockedUsersArray = sendPushToUser[#"blockedUsers"];
BOOL blocked = false;
for (NSString *username in blockedUsersArray) {
if ([username isEqualToString:currentUser.username]) {
blocked = true;
}
}
// If the user isn't blocked, send push
if (blocked == false) {
[PFCloud callFunctionInBackground:#"sendPushToUser"
// more cloud code to handle the notification...
You could also block the push notification in the Parse Cloud Code, with some JS.

How to send push notification to specific user in Parse? [duplicate]

I have successfully setup parse push notifications and in my installation table I have both an installation, and device token. What I'm really trying to do is send a push notification to certain users, rather than certain devices. How do I bing the installations table to the uses table, so that I can make a query by users and get back a deviceid to push to
From https://parse.com/docs/push_guide#top/iOS, section "Using Advanced Targeting".
You can even create relationships between your Installation objects
and other classes saved on Parse. To associate a PFInstallation with a
particular user, for example, you can simply store the current user on
the PFInstallation.
// Associate the device with a user
PFInstallation *installation = [PFInstallation currentInstallation];
installation[#"user"] = [PFUser currentUser];
[installation saveInBackground];
Now you can create a query on the installation table, where "user" is the user you want to send a push notification to.
Finally, use that query when constructing the push object.
Example in Objective-C (adjust accordingly, if you're sending the push in some other language):
PFQuery *pushQuery = [PFInstallation query];
[pushQuery whereKey:#"user" equalTo:someUser]; // where some user is the user object that is to receive a push notification
PFPush *push = [[PFPush alloc] init];
[push setQuery:pushQuery];
[push setMessage:#"Hi there!"];
[push sendPushInBackground];

Parse : How to send a push notification to everyone from iOS app?

is there a way to send a push notification to everyone directly from app, as in the console ?
if i try following code :
PFPush *push = [[PFPush alloc] init];
[push setMessage:#"Invio Push"];
[push sendPushInBackground];
looking at the consolle
it says that has been sent to 0 users,and it tried to send to channels i/o everyone.
If i send the message from console, i manage to send to everyone, without problem
Is there a way to achieve the same results from app ?
P.s.
naturally if I add
PFPush *push = [[PFPush alloc] init];
[push setChannel:#"Mychannel"];
[push setMessage:#"Invio Push"];
[push sendPushInBackground];
the push notification is sent correctly to "Mychannel" channel
Many thanks
Fabrizio
Yes you can also send push notifications directly from a mobile application. Remember that you need to have enabled this feature in the Parse app's settings tab by selecting "Yes" under the heading "Client push enabled?". There are several methods that can be called to send push notifications.
My Example:
// Create our Installation query
PFQuery *pushQuery = [PFInstallation query];
[pushQuery whereKey:#"deviceType" equalTo:#"ios"];
// Send push notification to query
[PFPush sendPushMessageToQueryInBackground:pushQuery
withMessage:#"TEST1234"];

Resources