iOS to Parse.com - SaveInBackground Object ID is null - ios

I am struggling to find why I am getting a null value when using SaveInBackgroundWithBlock to Parse.com. I am sure I am missing something, have tried both if (!error) and if(succeeded) with same result which is that the object is created but eventID (the objectID) is null... Any suggestions?
Thanks in advance!
[event saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
[CommonHelper hideBusyView];
EventObj *obj = [[EventObj alloc] init];
obj.eventID = event.objectId;
obj.eventName = strNameEvent;
obj.eventDateTime = self.dateEvent;
obj.eventAddress = strAddress;
NSLog(#"EventID: %#",self.eventObj.eventID);
PreviewInvite *invitepreview =[[PreviewInvite alloc] init];
invitepreview.eventObj = self.eventObj;
[self.navigationController pushViewController:invitepreview animated:YES];
}
else
{
NSString *errorString = [error userInfo][#"error"];
[CommonHelper showAlert:errorString];
[CommonHelper hideBusyView];
}
}]

Related

Facebook Photo Downloading

I am attempting to download Facebook albums of photos from a user in my app. Unfortunately although I do have an access token, I am getting zero albums from the requests. I am not getting an error, just getting zero. Why? If you would like to see any more code or ask more questions, just ask. Note that I have authorized the current user's Facebook permissions when they signed up, and I've since quit the app and opened it many times (don't think this would be an issue, since I have an access token..?)
- (void)getAlbums:(OLFacebookAlbumRequestHandler)handler {
if ([FBSDKAccessToken currentAccessToken]) {
// connection is open, perform the request
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
NSString *graphPath = #"me/albums?limit=100&fields=id,name,count,cover_photo";
if (self.after) {
graphPath = [graphPath stringByAppendingFormat:#"&after=%#", self.after];
}
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:graphPath parameters:nil];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
if (self.cancelled) {
return;
}
if (error) {
[OLFacebookAlbumRequest handleFacebookError:error completionHandler:handler];
return;
}
NSString *parsingErrorMessage = #"Failed to parse Facebook Response. Please check your internet connectivity and try again.";
NSError *parsingError = [NSError errorWithDomain:kOLErrorDomainFacebookImagePicker code:kOLErrorCodeFacebookImagePickerBadResponse userInfo:#{NSLocalizedDescriptionKey: parsingErrorMessage}];
id data = [result objectForKey:#"data"];
if (![data isKindOfClass:[NSArray class]]) {
handler(nil, parsingError, nil);
return;
}
NSMutableArray *albums = [[NSMutableArray alloc] init];
for (id album in data) {
if (![album isKindOfClass:[NSDictionary class]]) {
continue;
}
id albumId = [album objectForKey:#"id"];
id photoCount = [album objectForKey:#"count"];
id name = [album objectForKey:#"name"];
if (!([albumId isKindOfClass:[NSString class]] && [photoCount isKindOfClass:[NSNumber class]]
&& [name isKindOfClass:[NSString class]])) {
continue;
}
OLFacebookAlbum *album = [[OLFacebookAlbum alloc] init];
album.albumId = albumId;
album.photoCount = [photoCount unsignedIntegerValue];
album.name = name;
album.coverPhotoURL = [NSURL URLWithString:[NSString stringWithFormat:#"https://graph.facebook.com/%#/picture?type=small&access_token=%#", album.albumId, [FBSDKAccessToken currentAccessToken].tokenString]];
[albums addObject:album];
}
// get next page cursor
OLFacebookAlbumRequest *nextPageRequest = nil;
id paging = [result objectForKey:#"paging"];
if ([paging isKindOfClass:[NSDictionary class]]) {
id cursors = [paging objectForKey:#"cursors"];
id next = [paging objectForKey:#"next"]; // next will be non nil if a next page exists
if (next && [cursors isKindOfClass:[NSDictionary class]]) {
id after = [cursors objectForKey:#"after"];
if ([after isKindOfClass:[NSString class]]) {
nextPageRequest = [[OLFacebookAlbumRequest alloc] init];
nextPageRequest.after = after;
}
}
}
handler(albums, nil, nextPageRequest);
}];
}
else {
NSString *message = #"No Facebook user authentication found.";
handler(nil, [NSError errorWithDomain:kOLErrorDomainFacebookImagePicker code:kOLErrorCodeFacebookImagePickerNoOpenSession userInfo:#{NSLocalizedDescriptionKey: message}], nil);
}
}
//Code for fetching albums...
- (void)loadNextAlbumPage {
self.inProgressRequest = self.albumRequestForNextPage;
self.albumRequestForNextPage = nil;
[self.inProgressRequest getAlbums:^(NSArray/*<OLFacebookAlbum>*/ *albums, NSError *error, OLFacebookAlbumRequest *nextPageRequest) {
self.inProgressRequest = nil;
self.loadingIndicator.hidden = YES;
self.albumRequestForNextPage = nextPageRequest;
if (error) {
if (self.parentViewController.isBeingPresented) {
self.loadingIndicator.hidden = NO;
self.getAlbumError = error; // delay notification so that delegate can dismiss view controller safely if desired.
} else {
[self.delegate albumViewController:self didFailWithError:error];
}
return;
}
NSMutableArray *paths = [[NSMutableArray alloc] init];
for (NSUInteger i = 0; i < albums.count; ++i) {
[paths addObject:[NSIndexPath indexPathForRow:self.albums.count + i inSection:0]];
}
[self.albums addObjectsFromArray:albums];
if (self.albums.count == albums.count) {
// first insert request
[self.tableView reloadData];
} else {
[self.tableView insertRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationFade];
}
if (nextPageRequest) {
self.tableView.tableFooterView = self.loadingFooter;
} else {
self.tableView.tableFooterView = nil;
}
}];
}
//And when they signed up:
[[[FBSDKGraphRequest alloc] initWithGraphPath:#"me" parameters:#{ #"fields" : #"id,first_name,photos,picture.width(400).height(400)"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) { //etc etc the method continues.
FB authentication will give you a unique access_token for a particular set of permissions. To access user photos, you need to request the user_photos permission. Use the FBSDKLoginButton to request permissions.
loginButton.readPermissions = #[#"public_profile", #"email", #"user_photos"];
Once you have an access token with the required permissions, persist that locally (on the device) to reuse in future. If the access code is still valid, you won't need to request it again. If it becomes invalid (in case the user explicitly revoked permissions to your app), send them back to the login screen.

Pass data fetched from Cloudkit from one viewcontroller to another

I have a button that calls this function and also calls performSegueWithIdentifier. Segue occurs before the data is the two query returns data. How do i get round this?
-(void)recommendSomeone {
NSString *currentUserID = [NSString stringWithFormat:#"%#%#",#"KU",self.liaResponse[#"id"]];
CKContainer *myContainer = [CKContainer defaultContainer];
CKDatabase *publicDatabase = [myContainer publicCloudDatabase];
CKRecordID *currentUserRecordID = [[CKRecordID alloc] initWithRecordName:currentUserID];
CKReference *recordToMatch = [[CKReference alloc] initWithRecordID:currentUserRecordID action:CKReferenceActionNone];
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"contactList CONTAINS %#",recordToMatch];
CKQuery *query = [[CKQuery alloc] initWithRecordType:#"knotworkGhostUsers" predicate:predicate];
[publicDatabase performQuery:query inZoneWithID:nil completionHandler:^(NSArray *results, NSError *error) {
if (error) {
// Error handling for failed fetch from public database
NSLog(#"error querying knotwork users %#", error);
}
else {
// Display the fetched records
self.randomGhostUser = results[arc4random_uniform([results count])];
NSLog(#"this is the first name %#", self.randomGhostUser[#"firstname"]);
NSLog(#"knotwork ghost users for current user data returned ordinary title %#",results);
NSString* searchQuery = #" ";
NSString *kuTitle = [self.randomGhostUser[#"title"] lowercaseString];
NSArray *keyWords = #[#"developer",#"networking",#"sales manager",#"engineer",#"doctor",#"facility manager"];
for(NSString* keyWord in keyWords){
NSRange checkResult = [kuTitle rangeOfString:keyWord];
if(checkResult.location != NSNotFound){
searchQuery = [NSString stringWithFormat:#"%#%#%#",searchQuery,#" ",keyWord];
}
}
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"allTokens tokenmatches[cdl] %# AND contactList CONTAINS %#",searchQuery,recordToMatch];
CKQuery *query2 = [[CKQuery alloc] initWithRecordType:#"knotworkGhostUsers" predicate:predicate];
[publicDatabase performQuery:query2 inZoneWithID:nil completionHandler:^(NSArray *response, NSError *error) {
if (error) {
// Error handling for failed fetch from public database
NSLog(#"error querying knotwork users %#", error);
}
else {
// Display the fetched records
self.recommendedGhostUser = response;
NSLog(#"knotwork users data returned after recom %#", self.recommendedGhostUser);
}
}];
}
[self performSegueWithIdentifier:#"Recommend" sender:nil];
}];
}
emphasized text
You have to replace your segue and put it inside your second completion-block.
Because otherwise your completion-block will be called after you already have pushed the segue.
[publicDatabase performQuery:query2 inZoneWithID:nil completionHandler:^(NSArray *response, NSError *error) {
if (error) {
// Error handling for failed fetch from public database
NSLog(#"error querying knotwork users %#", error);
}
else {
// Display the fetched records
self.recommendedGhostUser = response;
NSLog(#"knotwork users data returned after recom %#", self.recommendedGhostUser);
//Put it in here
[self performSegueWithIdentifier:#"Recommend" sender:nil];
}
}];
Also you could use prepareForSegue to pass your value to the second controller:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Set Segue name from storyboard
if ([[segue identifier] isEqualToString:#"seguename"])
{
// Get reference to the destination view controller
YourViewController *vc = [segue destinationViewController];
// Pass any objects to the view controller here, like...
[vc setMyObjectHere:object];
}
}
(Link to segue-answer)

New Data save to Mutable Array in Parse not calling save function

I have a module that saves data based on user inputs from text fields and adds it to an array saved in Parse. Testing with pre-populated data the module works fine. However, if I go to add data where there previously wasn't any it causes the app to ignore the saving element all together. What is the best way to add new arrays to Parse where no previous data existed? Here is the existing code:
- (IBAction)saveButton:(id)sender
{
[getData showGlobalProgressHUDWithTitle:#"Saving Test"];
PFQuery *tankQuery = [PFQuery queryWithClassName:#"WaterTests"];
[tankQuery whereKey:#"tankObjectId" equalTo:_passedValue];
[tankQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error)
{
for (PFObject *object in objects)
{
calciumArray = [object valueForKey:#"calciumArray"];
nitrateArray = [object valueForKey:#"nitrateArray"];
phosArray = [object valueForKey:#"phosphateArray"];
salinityArray = [object valueForKey:#"salinityArray"];
alkArray = [object valueForKey:#"alkArray"];
phArray = [object valueForKey:#"phArray"];
tempArray = [object valueForKey:#"tempArray"];
[calciumArray addObject: addCalcium.text];
[nitrateArray addObject: addNitrate.text];
[phosArray addObject: addPhosphate.text];
[salinityArray addObject: addSalinity.text];
[alkArray addObject: addAlk.text];
[phArray addObject: addPH.text];
[tempArray addObject: addTemp.text];
[object saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error)
{
NSLog(#"Something happened");
[getData dismissGlobalHUD];
[self hideTestView];
}
else
{
NSLog(#"Nothing happened: %#", error);
}
[self resignFirstResponder];
[_chartView reloadData];
}];
}
}
}];
}
I know that I'm close, but don't quite understand why it's not firing off the saving code. I believe its because I'm trying to retrieve objects that are empty first, but I could be wrong about that. Anyone have any advice for this?
UPDATE Here is the ViewDidLoad Code as it pertains to retrieving the data.
- (void)viewDidLoad
{
self.title = #"Water Quality";
statQuery = [PFQuery queryWithClassName:#"WaterTests"];
[statQuery whereKey:#"tankObjectId" equalTo:_passedValue];
[statQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error)
{
if (!error)
{
for (PFObject *object in objects)
{
[statQuery whereKey:#"tankObjectId" equalTo:_passedValue];
calciumArray = [object valueForKey:#"calciumArray"];
_footerView.sectionCount = calciumArray.count;
NSLog(#"CALCIUM ARRAY: %#", calciumArray);
nitrateArray = [object valueForKey:#"nitrateArray"];
NSLog(#"NITRATE ARRAY: %#", nitrateArray);
phosArray = [object valueForKey:#"phosphateArray"];
NSLog(#"PHOSPHATE ARRAY: %#", phosArray);
salinityArray = [object valueForKey:#"salinityArray"];
NSLog(#"SALINITY ARRAY: %#", salinityArray);
alkArray = [object valueForKey:#"alkArray"];
NSLog(#"ALKALINITY ARRAY: %#", alkArray);
phArray = [object valueForKey:#"phArray"];
NSLog(#"PH ARRAY: %#", phArray);
tempArray = [object valueForKey:#"tempArray"];
NSLog(#"TEMPERATURE ARRAY: %#", tempArray);
}
}
if (calciumArray == nil || [calciumArray count] == 0)
{
NSLog(#"You should probably fire off the new test function here.");
[_chartView setUserInteractionEnabled:NO];
[self newTest:self];
NSLog(#"Error: %#", error);
}
}];
This is the only other time the data is mentioned at all in the view. I allocate and initialize the arrays elsewhere, but I don't think that's the problem considering existing arrays pull and save just fine.
(PFObject *object in objects)
{
calciumArray = [object valueForKey:#"calciumArray"];
.
.
. //Other object for array
[arrayMu] [calciumArray addObject: addCalcium.text]; //Add in NSMutableArray
.
.
.
[objects save]; //Instead of saveinbackground.
}
Try this out. Also do reply back in time as after a long time I had would have to read all your query again as not in touch with it.
UPADTE...
-(IBAction)updateButton:(id)sender
{
PFQuery *query = [PFQuery queryWithClassName:#"UserDetail"];
NSString *str =self.nameTextField.text;
[query whereKey:#"name" containsString:str];
[query getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error)
{
if (!error)
{
NSLog(#"Successfully retrieved: %#", [object objectId]); //I retrieve the object succesfully
object[#"job"] = self.jobTextField.text; //Made changes to it.
object[#"hobby"] = self.hobbyTextField.text;
[object saveInBackground]; //Again saved it in background
}
else
{
NSLog(#"Error: %#", [error localizedDescription]);
} }];
}
Then I checked my parse db and my data was modified.
I was able to properly add a new array from a single object if nothing else was available by plainly adding a new object to Parse:
- (IBAction)saveButton:(id)sender
{
[getData showGlobalProgressHUDWithTitle:#"Saving Test"];
PFQuery *tankQuery = [PFQuery queryWithClassName:#"WaterTests"];
[tankQuery whereKey:#"tankObjectId" equalTo:_passedValue];
PFObject *testObject = [[PFObject alloc] initWithClassName:#"WaterTests"];
[tankQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (objects.count == 0)
{
[testObject setObject:_passedValue forKey:#"tankObjectId"];
[testObject addObject:addCalcium.text forKey:#"calciumArray"];
[testObject addObject:addNitrate.text forKey:#"nitrateArray"];
[testObject addObject:addPhosphate.text forKey:#"phosphateArray"];
[testObject addObject:addSalinity.text forKey:#"salinityArray"];
[testObject addObject:addAlk.text forKey:#"alkArray"];
[testObject addObject:addPH.text forKey:#"phArray"];
[testObject addObject:addTemp.text forKey:#"tempArray"];
[testObject saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error)
{
[getData dismissGlobalHUD];
[self hideTestView];
NSLog(#"Something, somewhere, saved.");
}
else
{
NSLog(#"HOORAY ERROR: %#", error);
}
[_chartView reloadData];
}];
}
However, I also had to check to see if there were any objects to begin with. If there were not any, simply add them in new. If there were, I had to run the code to query the database and add a for loop for every object that was found with the given criteria:
else if (objects.count != 0)
{
for (PFObject *object in objects)
{
[object addObject:addCalcium.text forKey:#"calciumArray"];
[object addObject:addNitrate.text forKey:#"nitrateArray"];
[object addObject:addPhosphate.text forKey:#"phosphateArray"];
[object addObject:addSalinity.text forKey:#"salinityArray"];
[object addObject:addAlk.text forKey:#"alkArray"];
[object addObject:addPH.text forKey:#"phArray"];
[object addObject:addTemp.text forKey:#"tempArray"];
[object saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error)
{
if (!error)
{
[getData dismissGlobalHUD];
[self hideTestView];
[_chartView reloadData];
NSLog(#"Here we go again");
}
}];
}
}
}];
}
I'm submitting this as my own answer and offering this to the community wiki to help others figure out similar problems. Problem: SOLVED!

Challenging Online Database Persistence w/ Core Data?

This is my first time doing any work with database persistence/maintenance online, so I apologize in advance for my sloppy code. My app consists of the user creating a bunch of athletes and having their data save online so they can be accessed from any device. This works fantastically, except the athletes each get saved twice online, and it's making me want to rip my hair out. I've checked my code several hundred times, but I just can't seem to find why athletes are being saved twice on the server, resulting in 2 locally as well. I'm utilizing the Parse.com framework. Am I missing something?
The following method gets called from a pull down to refresh on a table view controller.
- (void)getParseData {
NSLog(#"GET PARSE DATA WAS CALLED");
if(self.syncing != TRUE){
NSLog(#"GET PARSE DATA RAN");
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateStyle = NSDateFormatterLongStyle;
PFQuery *query = [PFQuery queryWithClassName:#"Athlete"];
[self populateAthleteArray];
if (self.athleteArray.count == 0) {
NSLog(#"ATHLETE ARRAY IS EMPTY");
// If the athlete array has no objects, download all objects from the database.
[query findObjectsInBackgroundWithBlock: ^(NSArray *objects, NSError *error) {
self.syncing = TRUE;
if (!error) {
self.syncing = FALSE;
for (PFObject * object in objects) {
Athlete *newAthlete = [NSEntityDescription insertNewObjectForEntityForName:#"Athlete" inManagedObjectContext:_managedObjectContext];
newAthlete.first = object[#"first"];
newAthlete.last = object[#"last"];
newAthlete.updatedAt = [dateFormatter stringFromDate:[object updatedAt]];
newAthlete.objectId = [object objectId];
[_managedObjectContext save:nil];
}
self.syncing = FALSE;
}
else {
self.syncing = FALSE;
NSLog(#"Error: %# %#", error, [error userInfo]);
}
if(self.needToUploadArray.count > 0){
[PFObject saveAllInBackground:self.needToUploadArray target:nil selector:#selector(emptyUploadArray)];
}
}];
[self populateAthleteArray];
[self.tableView reloadData];
}
else {
NSLog(#"ATHLETE ARRAY HAS ATHLETES ALREADY");
// Athlete array has athletes already
NSMutableArray *athletesToUpload = [NSMutableArray array];
// Placeholder array for athletes that aren't in the database.
for (Athlete *athlete in athleteArray) {
if (athlete.objectId.length == 0 || athlete.objectId == nil) {
// If the objectId is nil, it wasn't uploaded to the database. Add to placeholder array.
[athletesToUpload addObject:athlete];
}
}
[query findObjectsInBackgroundWithBlock: ^(NSArray *objects, NSError *error) {
self.syncing = TRUE;
if (!error) {
// Downloaded all athletes successfully
self.syncing = FALSE;
BOOL found = FALSE;
[self populateAthleteArray];
NSMutableArray *athletesToDelete = [NSMutableArray array];
for (Athlete * athlete in athleteArray) {
for (PFObject * object in objects) {
// Check to see each local athlete exists in the online database
if ([object.objectId isEqualToString:athlete.objectId]) {
// Athlete was find in the online database
found = TRUE;
break;
}
}
if (found != TRUE) {
NSLog(#"%# was not found online.",athlete.first);
if(athlete.objectId.length > 0){
NSLog(#"%# was deleted online. delete them locally",athlete.first);
[athletesToDelete addObject:athlete];
}
else{
// No athlete in the local database matched any of the athletes online
PFObject *onlineAthlete = [PFObject objectWithClassName:#"Athlete"];
onlineAthlete[#"first"] = athlete.first;
onlineAthlete[#"last"] = athlete.last;
PFFile *imageFile = [PFFile fileWithName:[NSString stringWithFormat:#"%#%#MedicalRelease.jpg", athlete.first, athlete.last] data:athlete.medical_release_image];
onlineAthlete[#"medical_release_image"] = imageFile;
[onlineAthlete saveInBackgroundWithBlock: ^(BOOL succeeded, NSError *error) {
self.syncing = TRUE;
if (succeeded) {
NSLog(#"SAVED SUCCESSFULLY");
self.syncing = FALSE;
PFQuery *query = [PFQuery queryWithClassName:#"Athlete"];
[query orderByDescending:#"createdAt"];
[query getFirstObjectInBackgroundWithBlock: ^(PFObject *object, NSError *error) {
Athlete *athleteToChange = [self findAthlete:athlete.objectId];
[athleteToChange setObjectId:[object objectId]];
[_managedObjectContext save:nil];
}];
}
}];
}
}
found = FALSE;
}
if(athletesToDelete.count > 0){
for(id athlete in athletesToDelete){
NSManagedObject *eventToDelete = athlete;
[_managedObjectContext deleteObject:eventToDelete];
[athleteArray removeObjectAtIndex:[athleteArray indexOfObject:athlete]];
[self.tableView reloadData];
NSError *error = nil;
if (![_managedObjectContext save:&error]) {
NSLog(#"there is an error: %#", error);
}
}
}
for (PFObject *object in objects) {
// Loop through every athlete downloaded
for (Athlete * athlete in athleteArray) {
// For every object downloaded, compare it to every athlete in the local database.
if ([object.objectId isEqualToString:athlete.objectId]) {
// If the object's id matches the local athletes id, we found the object
if ([object updatedAt] >= [dateFormatter dateFromString:athlete.updatedAt]) {
// If the object has been updated more recently than the athlete, update the local athlete
Athlete *sameAthlete = [self findAthlete:athlete.objectId];
sameAthlete.first = object[#"first"];
sameAthlete.last = object[#"last"];
sameAthlete.updatedAt = [dateFormatter stringFromDate:[object updatedAt]];
sameAthlete.address = object[#"address"];
sameAthlete.objectId = [object objectId];
[_managedObjectContext save:nil];
}
found = TRUE;
// The athlete was found in the database
break;
}
}
if (found != TRUE) {
// We looped through all the local athletes, the object downloaded isn't in the local database; add them.
Athlete *athlete = [NSEntityDescription insertNewObjectForEntityForName:#"Athlete" inManagedObjectContext:_managedObjectContext];
athlete.first = object[#"first"];
athlete.last = object[#"last"];
athlete.objectId = [object objectId];
athlete.address = object[#"address"];
athlete.updatedAt = [dateFormatter stringFromDate:[object updatedAt]];
[_managedObjectContext save:nil];
}
// Reset flag var
found = FALSE;
}
}
else {
self.syncing = FALSE;
NSLog(#"Error: %# %#", error, [error userInfo]);
}
self.syncing = FALSE;
}];
if (athletesToUpload.count > 0) {
for (Athlete *athlete in athletesToUpload) {
PFObject *upload = [PFObject objectWithClassName:#"Athlete"];
upload[#"first"] = athlete.first;
upload[#"last"] = athlete.last;
PFFile *imageFile = [PFFile fileWithName:[NSString stringWithFormat:#"%#%#MedicalRelease.jpg", athlete.first, athlete.last] data:athlete.medical_release_image];
upload[#"medical_release_image"] = imageFile;
[upload saveInBackgroundWithBlock: ^(BOOL succeeded, NSError *error) {
if (succeeded) {
PFQuery *uploadQuery = [PFQuery queryWithClassName:#"Athlete"];
[uploadQuery orderByDescending:#"createdAt"];
[uploadQuery getFirstObjectInBackgroundWithBlock: ^(PFObject *object, NSError *error) {
[athlete setObjectId:[object objectId]];
}];
}
}];
}
}
[self populateAthleteArray];
[self.tableView reloadData];
}
}
}
In the branch marked by the comment // No athlete in the local database matched any of the athletes online you are creating a new PFObject and saving it to Parse. In my understanding, this should not be correct, since the athlete is not in the local db but online.

reportAchievementWithCompletionHandler deprecated in iOS7 but replacement not specified

Has anyone found the replacement for
[GKAchievement reportAchievementWithCompletionHandler]?
Typically when things are deprecated the docs indicate a replacement. Not so with this one so far and I wanted to cross this off the list of possible causes of another issue we are seeing.
Was looking for the same info and saw your post, here is what I went with after not finding anything either:
NSArray *achievements = [NSArray arrayWithObjects:achievement, nil];
[GKAchievement reportAchievements:achievements withCompletionHandler:^(NSError *error) {
if (error != nil) {
NSLog(#"Error in reporting achievements: %#", error);
}
}];
Here is apple's full code (same/similar to Silly Goose's Answer)
- (void) completeMultipleAchievements
{
GKAchievement *achievement1 = [[GKAchievement alloc] initWithIdentifier: #"DefeatedFinalBoss"];
GKAchievement *achievement2 = [[GKAchievement alloc] initWithIdentifier: #"FinishedTheGame"];
GKAchievement *achievement3 = [[GKAchievement alloc] initWithIdentifier: #"PlayerIsAwesome"];
achievement1.percentComplete = 100.0;
achievement2.percentComplete = 100.0;
achievement3.percentComplete = 100.0;
NSArray *achievementsToComplete = [NSArray arrayWithObjects:achievement1,achievement2,achievement3, nil];
[GKAchievement reportAchievements: achievementsToComplete withCompletionHandler:^(NSError *error)
{
if (error != nil)
{
NSLog(#"Error in reporting achievements: %#", error);
}
}];
}
This works in iOS7 with no issues.
- (void)checkAchievements
{
if(myScore >= 25000){
GKAchievement *achievement= [[GKAchievement alloc] initWithIdentifier:#"Achiev1"];
achievement.percentComplete = 100.0;
achievement.showsCompletionBanner = YES;
[self Achievements:achievement];
}
}
-(void)Achievements:(GKAchievement*)achievement {
NSArray *achievements = [NSArray arrayWithObjects:achievement, nil];
[GKAchievement reportAchievements:achievements withCompletionHandler:^(NSError *error) {
if (error != nil) {
NSLog(#"Error in reporting achievements: %#", error);
}
}];
}

Resources