I have a random messaging app using parse.com as a backend. I am saving the messages in a class called "Messages" with the keys:
"messageBody"(which is the content of the message) and
"senderId"(which is the sender id of course)
After this gets saved in my Messages class, I am using cloud code to query 3 random users and send this message to them.
My question is which is the best way to do this because I foresee errors in my current method. The current method i am using is after the user presses send I save the message to Parse.com and then I call the "send to 3 random users" cloud function, but what if my message has not been successfully saved to the parse backend before the cloud function is implemented?
-(IBAction)send{
PFObject *message = [PFObject objectWithClassName:#"Message"];
[message setObject:self.messageContent forKey:#"messageBody"];
[message setObject:[[PFUser currentUser] objectId] forKey:#"senderId"];
[message saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error){
if(error){
//show alert with error
}
else{
//everything was successful
}
}];
[PFCloud callFunctionInBackground:#"sendToThreeRandomUsers" withParameters:#{}
block:^(NSString *result, NSError *error) {
if (!error) {
//cloud function was a success!
}
}];
}
Basically I want to know if there is a way that whenever there is a new object in the Messages class I can say send this to 3 random users from my parse backend rather than calling it from my users device?
Or Should I just totally skip saving it to my parse backend and just send it straight to my cloud code as a parameter of the cloud function? Then save it to my backend. what if the messageBody is very big though?
So this question really isnt about code but the way to structure it.
Wish I could use Hector Ramos as a tag for this question
Why don't you write a afterSave method for your Messages class. Whenever new message is saved successfully, this method (Parse.Cloud.afterSave("Messages", function(request, response) {..}) is executed and 3 random users can be selected. The API explanation is in below link;
https://parse.com/docs/cloud_code_guide#functions-onsave
Hope this helps,
Regards.
Related
I tried to get the user details using MSGraph SDK in iOS using below API method. Iam successfully received the user details all the time. But when user charged their password or update their credentials, i received the oauthConnection Error: only in log. And i didn't receive any call back in the below API. Why it is not responding back when any kind of error occurred? Please help me. Thanks in advance.
[MSGraphClient setAuthenticationProvider:self.authProvider.authProvider];
self.graphClient = [MSGraphClient client];
[[[self.graphClient me]request]getWithCompletion:^(MSGraphUser *response, NSError *error) {
if(!error){
// Im able to get back here
}
else{
//Im not received any call back here when user changed their password or any error occurred.
[self.authProvider disconnect];
}
}];`
I am kinda new to MS Graph, so I might be missing something, but your graphClient declaration seems a little bit poor to me.
Try to download this sample: https://github.com/Azure-Samples/active-directory-dotnetcore-daemon-v2
And check it's declaration of graphClient.
You might be missing the part which refreshes the token?
I am trying to use the syncing feature of contentful so I will only fetch new or updated content form my space. From the documentation it says with the fetch I need a parameter of "initial"="true", which I am trying below, but I get 400 error. Has someone used this before? thanks
[self.client fetchEntriesMatching:#{#"content_type": #"navigationPage",
#"locale":countryCode,
#"initial":#"true"
}
success:^(CDAResponse *response, CDAArray *array) {
} failure:^(CDAResponse *response, NSError *error) {
}];
`
You're calling the entirely wrong method. You should be calling the initialSynchronizationWithSuccess:failure:which is documented here http://cocoadocs.org/docsets/ContentfulDeliveryAPI/1.10.4/Classes/CDAClient.html#//api/name/initialSynchronizationWithSuccess:failure:
That will in turn call the sync endpoint of the Contentful API with the initial parameter set to true. It will return a CDASyncedSpace object that can be used for further requests. Documented here http://cocoadocs.org/docsets/ContentfulDeliveryAPI/1.10.4/Classes/CDASyncedSpace.html
I use Stripe in Parse Cloud Code and receive a Stripe ID (String), but I want to send that stripe id back to Xcode. What is the best way of doing this?
I've tried to first of all send the stripe ID to Parse, and in Xcode I do a fetch...
But I think that's a bad idea because if there are multiple users processing the payments at same time, it's hard to get the right stripe ID for the user.
To return data from cloud code, take a look at this tutorial post.
Basically all you have to do is return the stripe id like this
response.success(stripeId);
Receiving data looks like this :
[PFCloud callFunctionInBackground:#"averageStars" withParameters:params block:^(NSString *stripeId, NSError *error) {
if (!error) {
// code
}
}];
I'm getting to know Parse and am already having a tough problem.
I'm working with the User Login flow. I need to be able to delete the User object I've just created. Problem is, on the Dashboard, I only have the Installation data table.
I realized I wasn't explicitly saving this user object, although locally (on iOS) I could log in with the currentUser object credentials. So I thought I'd remove the install from the simulator and try again (hey, since my data wasn't on the dashboard.)
Now I tried re-installing the app, using the same username/pass, and Parse SDK is telling me these are already taken!
So the question is, where is this User, and how do I completely remove the data so I can start over again?
2015-10-15 16:37:29.999 ParseApp[21428:2003831] [Error]: username myUserName already taken (Code: 202, Version: 1.8.5)
This doesn't solve the problem, but is kind of like a workaround for testing purposes. I made a method:
- (IBAction)pressedDeleteSelf:(id)sender
{
[[PFUser currentUser] deleteInBackgroundWithBlock:^(BOOL succeeded, NSError * _Nullable error) {
if (succeeded) {
[PFUser logOut];
[self performSegueWithIdentifier:#"unwindSignedOut" sender:self];
}
}];
}
Which then allows me to re-create a user with the same credentials. I still have no idea why the PFUser table does not show up in the Dashboard.
Oh myyy... how silly do I feel. With all these different tutorials I've been running, apparently I had been doing all this stuff using the wrong AppID and Client Key. A rookie mistake, but hopefully someone else doesn't have to trip on this.
To be clear, solution is to make sure your App ID and Client key in the Parse dashboard match what you call in code:
// Initialize Parse.
[Parse setApplicationId:PARSE_APP_ID
clientKey:PARSE_CLIENT_KEY];
Embarrassed...
I'm stuck in a situation where I am not able to use the structured 'askfor' or 'send' requests through IOS SDK. I always get an error which says that facebook could not find any object with that particular object id. I created the object by using the Object Types section under the Open Graph section in the App settings page. I have tried the same thing with test user account too, but no avail.
Used this as the guide - https://developers.facebook.com/docs/games/requests/v2.2#gifting
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
toList, #"to", // Comma separated string of FB ids.
dataStr, #"data", // Data to be sent with request
objectId, #"object_id", // Object as retrieved from Object Types
#"askfor", #"action_type", // Preset action type [send/askfor/turn]
];
[FBWebDialogs presentRequestsDialogModallyWithSession:nil
message:messageStr
title:titleStr
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
I get an error within the returnUrl (error 100) which says facebook cannot find an object with the given ID.
Have been stuck at this for quite sometime now, any help greatly appreciated! Thanks in advance!