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
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 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 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.
I have been struggling to find a clean solution for this problem for a few I have created an app which makes multiple restful web service requests which work fine however part of the request the login details or API Key could expire and I need to be able to handle this and present the user the login screen again.
In my API Client class I am doing the following which works fine, however because the app does multiple web service requests I am seeing the UI AlertView multiple times.
Any ideas on how I can make this block of code only run once for the first error which occurs and only show one alert view?
AFJSONRequestOperation *operation = [[AFJSONRequestOperation alloc] initWithRequest:apiRequest];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
completionBlock(responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSInteger statusCode = [operation.response statusCode];
if (statusCode == 401) {
[UIAlertView error:#"Your session has expied, please log in again."];
[[NSNotificationCenter defaultCenter]
postNotificationName:#"Logout"
object:self];
} else {
completionBlock([NSDictionary dictionaryWithObject:[error localizedDescription] forKey:#"error"]);
}
}];
One way would be to create a global variable which contains the current login status. You should check this login status before a request or before the success/failure blocks if the requests are not chained together.
A better approach would be to create a NSOperationQueue to manage the AFJSONRequestOperation objects. This would give you more control over the lifespan of each request. If one returns a 401 then you could cancel all the operations in the queue.
You can find more about creating and using queue here at this link.
Typically you encounter a similar issue when initialising the shared instance of a singleton object that you want to avoid performing the initialisation more than once.
One way to solve this is using Grand Central Dispatch's dispatch_once, as shown below, which is also included in Xcode as a default snippet (GCD: Dispatch Once). In your case you'd present the alert inside the block you pass to dispatch_once.
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
/*code to be executed once*/
});
I am posting a request and checking for errors like so:
// Send request out on a background thread
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
if ([urlResponse statusCode] == 200) {
NSLog(#"Tweet Successful");
}else {
NSLog(#"Tweet Failed");
if (responseData) {
// Use the NSJSONSerialization class to parse the returned JSON
NSError *jsonError;
NSArray *requestResponse =
[NSJSONSerialization JSONObjectWithData:responseData
options:NSJSONReadingMutableLeaves
error:&jsonError];
if (requestResponse) {
NSLog(#"%#",requestResponse);
} else {
NSLog(#"%#",jsonError);
}
}
}
}];
});
It seems to work fine, so far as the request is concerned. My intention was to queue the request on failure and try again at a later date, or not depending on the error and how many attempts had failed thus far.
The problem I have is that I find it frequently appears to fail, with error 34 "Page not Found" where in fact the request did succeed, was posted as intended and can be seen clear as day in twitter stream.
Now, if I can't trust the error code returned then I can't really go on and keep retrying. How do I know for sure if it succeeds or fails?
RECENT OBSERVATIONS:
Recently, I tried to post a photo from Apple photo app directly and it sent me an alert that read "Tweet may not have been successful". That is funny, because that is basically what I was coming to as my only option in this case. This makes me think that even Apple had to acknowledge that there is not way to tell for sure that post failed when the return does not confirm it.
according to every example found in researching this problem, none of which use any other API than what you are using, and including this example from twitter's own documentation for posting a photo to the API, none of them check the urlResponse code first.
the most that ever seems to be done is this example from twitter's documentation where a GET is performed and then the response is processed. notice that it checks the responseData first, and if it exists, it is simply treated like success. only if there is no responseData is there an attempt to bother looking at the error. the example does not bother with the urlResponse … and neither does any other example i saw in 10 minutes of googling.
(finally, i doubt this matters, or it may be because you cleaned up the example for the display, but you're processing the error on the main-queue when you are not performing any UI. you could do the processing in the handler immediately, and pass along whatever post-processing you do to whatever UI you are trying to display it with. i doubt post-processing the response in the main-queue as opposed to the queue of the handler (as shown in both examples cited here and all other examples i've seen) is really causing a problem, but i wonder if it might cut down on the incidence of false negatives you are seeing. at the very least, it will make your response and any UI display of the response cleaner and more efficient.)