Can't retrieve geopoint with geoPointForCurrentLocationInBackground - ios

I'm trying to retrieve the current user's current geopoint, but nothing happens when I call the geoPointForCurrentLocationInBackground:. I can't log the NSLog's from the block, however the other NSLog appears in the console.
- (IBAction)whereCurrentUser:(id)sender {
[PFGeoPoint geoPointForCurrentLocationInBackground:^(PFGeoPoint *geoPoint, NSError *error) {
if (geoPoint) {
NSLog(#"GEOPOINT %#", geoPoint);
}
else
{
NSLog(#"ERROR");
}
}];
NSLog(#"BUTTON TAPPED");
}
Do I need to implement something else? The documentation is quite clear therefore I can't figure out what could be the problem.

There's a solution posted on Parse.com PFGeoPoint.geoPointForCurrentLocationInBackground not doing anything. Basically update Parse to the latest version and add the NSLocationWhenInUseUsageDescription key to your Info.plist, this is a change made in iOS 8 and is needed whenever you want to use an users location within your app.

Related

Google Add Place API is not giving any response after added new location into Google places API - iOS

I need to add a new business place by using the google places API which is not already in google places database. For this we have used addPlace: callback:^ I believe this method once successfully added a new business location that call backs send a response to us and Places API are reviewed and, if approved, added to the global places database.
I have used the same call back method, but can't get any response from it.
My code is below,
GMSPlacesClient *placesClient;
[placesClient addPlace:userAddedPlace callback:^(GMSPlace *place, NSError *error) {
if (error != nil) {
NSLog(#"User Added Place error %#", [error localizedDescription]);
return;
}
NSLog(#"Added place with placeID %#", place.placeID);
NSLog(#"Added Place name %#", place.name);
NSLog(#"Added Place address %#", place.formattedAddress);
}];
We keep the location details in this object userAddedPlace
Is there any issue in this code? help me out why i didn't get the response after call this method. Thanks in advance.
Did you init placesClient object? try GMSPlacesClient *placesClient = [GMSPlacesClient sharedClient];

Azure Mobile Service Offline Data Sync - The item provided was not valid

I am using Azure Mobile Service as a backend for an iOS app. I have set up everything to work with offline sync which allows me to view, add, or modify data even when there is no network connection. I am now into testing and I run into an error: "The item provided was not valid" when I try to synchronize data.
Here's what I am doing:
I add a new athlete to the syncTableWithName:#"Athlete" with this:
NSDictionary *newItem = #{#"firstname": #"Charles", #"lastname": #"Lambert", #"laterality" : #"Orthodox"};
[self.athletesService addItem:newItem completion:^{
NSLog(#"New athlete added");
}];
Here's the addItem function:
-(void)addItem:(NSDictionary *)item completion:(CompletionBlock)completion
{
// Insert the item into the Athlete table
[self.syncTable insert:item completion:^(NSDictionary *result, NSError *error)
{
[self logErrorIfNotNil:error];
// Let the caller know that we finished
dispatch_async(dispatch_get_main_queue(), ^{
completion();
});
}];
}
For now everything is fine and the item is in the syncTable. The problem is when I try to synchronize with the Azure Mobile Service. Here's the syncData function I am calling:
-(void)syncData:(CompletionBlock)completion
{
// push all changes in the sync context, then pull new data
[self.client.syncContext pushWithCompletion:^(NSError *error) {
[self logErrorIfNotNil:error];
[self pullData:completion];
}];
}
The pushWithCompletion gets me the error: "The item provided was not valid." and same for the pullData function that gets called after:
-(void)pullData:(CompletionBlock)completion
{
MSQuery *query = [self.syncTable query];
// Pulls data from the remote server into the local table.
// We're pulling all items and filtering in the view
// query ID is used for incremental sync
[self.syncTable pullWithQuery:query queryId:#"allAthletes" completion:^(NSError *error) {
[self logErrorIfNotNil:error];
// Let the caller know that we finished
dispatch_async(dispatch_get_main_queue(), ^{
completion();
});
}];
}
I have tried inserting directly in the MSTable and that works fine. It's really when I am using the MSSyncTable that I run into this error. Although when I insert data manually in my database and that I synchronize my context I can fetch data and display within my UITableView.
Lookin forward to see what you guys think about this. Thanks a lot!
I just edited my question thanks to #phillipv.
When I add an item using NSDictionary just like I did I run into the error "The item provided was not valid". So I tried adding an item by first inserting it to my managedObjectContext and then calling:
NSDictionary *dict = [MSCoreDataStore tableItemFromManagedObject:newAthlete];
I then I get the error when I try to sync: "The item provided did not have a valid id."
I feel like I am experiencing a circle.. :S
#Charley14, you can work around the bug by adding the following handler.
- (void)tableOperation:(nonnull MSTableOperation *)operation onComplete:(nonnull MSSyncItemBlock)completion
{
NSMutableDictionary *rwItem = [NSMutableDictionary dictionaryWithDictionary:operation.item];
// Temporary workaround
[rwItem removeObjectsForKeys:#[ #"relationship1", #"relationship2"]];
operation.item = rwItem;
[operation executeWithCompletion:completion];
}
The tableOperation:onComplete: handler is simply removing keys that correspond to the relationships. You will have to replace 'relationship1', 'relationship2' in the code snippet with names of actual relationships in your application.
Once the bug (https://github.com/Azure/azure-mobile-services/issues/779) is fixed, this workaround can be removed.
This appears to be a bug in the iOS SDK, as the Many to One relationship is not supposed to be exposed in the object given to the operation during a Push call.
Created the following bug with more details on GitHub: https://github.com/Azure/azure-mobile-services/issues/779
The cause of the error message is due to the fact that the relationship is a NSSet on the object, and the NSJSONSerializer throws as it does not know how to convert that to JSON.

saveInBackground is not being called

NSLog(#"pressed");
[_order setObject:_placeChosen forKey:#"place"];
_order[#"place"] = _placeChosen;
//[_order saveEventually];
[_order saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
NSLog(#"saving...");
if(succeeded){
NSLog(#"succeeded dude");
[self performSegueWithIdentifier:#"pickDate" sender:self]; }
else{
NSLog(#"error");
NSLog([error debugDescription]);
}
}];
That's my code. As you can see, I've logged all the possible places and here is the crazy thing: There is no error! The "error" won't show up nor will the debugDescription. "saving..." is not showing up either. however, "pressed" DOES show up. I thought it was faulty network connection but i waited for a while, tried a bunch of times, went to different places and it STILL doesn't work. Is this a bug? Or is there another way to do this?
It turns out that in my prepareForSegue in the previous controller, I had spelled the name of the segue identifier wrong so that the _order wasn't being transferred over thus it was nil. Fixing the spelling fixed the issue. Although, Parse should really give an error saying that the PFObject is nil so it can't be saved.

FireBase removeValue in iOS not always persisting to database

I am testing FireBase in my iOS app and it is pretty amazing so far but it seems if I use [fb removeValue]; when I am not connected the change is not always reflected any where else.
Here is my code:
-(void) deleteFromFirebase {
Firebase *fb =[[Firebase alloc] initWithUrl:[NSString stringWithFormat:#"https://repzio.firebaseio.com/orders/%#/%#",self.purchaseOrder.ManufacturerID, self.purchaseOrder.OrderGUID]];
[fb removeValue];
}
Obviously this causes issues when the app need to remove data and have it persisted. Has anyone else run into this issue? Am I handling this wrong?
I would use blocks!
[fb removeValueWithCompletionBlock:^(NSError *error, Firebase *ref) {
if (!error) {
// Save worked
}
else {
// cache for later, or notify user that there was an error and they should try again.
}
}];

gamecenter turnbased save match data out of turn

Any chance I can save/update matchdata even when it is not my turn?
[currentMatch saveCurrentTurnWithMatchData:data completionHandler:^(NSError *error) {
if (error)
{ }];
The above code can be used if it is still this user's turn, but what if it is not this user's turn? How do I send data between two players?
As of iOS 6.0, you cannot. :(
You can save match data without advancing the turn (assuming you are
the current player). see - saveCurrentTurnWithMatchData:completionHandler:
You can end a game out of turn. see - participantQuitOutOfTurnWithOutcome:withCompletionHandler:
However, you cannot update match data out of turn.
GKTurnBasedMatch Reference
Try this
- (void) advanceTurn
{
NSData *updatedMatchData = [this.gameData encodeMatchData];
NSArray *sortedPlayerOrder = [this.gameData encodePlayerOrder];
this.MyMatch.message = [this.gameData matchAppropriateMessage];
[this.myMatch endTurnWithNextParticipants: sortedPlayerOrder turnTimeOut: GKTurnTimeoutDefault
matchData: updatedMatchData completionHandler ^(NSError *error) {
if (error)
{
// Handle the error.
}
}];
}

Resources