iOS Facebook SDK - getting user location - ios

Using FBLoginView I am able to log in users and get a FBGraphUser object which holds data in the following structure:
FBGraphUser
|---username
|---email
|---id<FBGraphPlace> location
|---place_name
|---id<FBGraphLocation> location
|---city
|---street
|---latitude/longitude
See Facebook's documentation for a better picture :)
I am able to get user's FBGraphPlace location with correct place_name data but the FBGraphLocation comes null.
I'd like access to this data, and this is where I'm stumped. I ensured the user's location information is publicly visible, and I set the readPermissions of FBLoginView to include #"user_location".
Does anyone know where I could be making my mistake? Thanks!
Edit - Solution: My Facebook address field was empty. I mistook 'current city' for address.

Try to do this:
id<FBGraphUser> fbUser = (id<FBGraphUser>)user;
id<FBGraphPlace> fbPlace = [fbUser location];
id<FBGraphLocation> fbLocation = [fbPlace location];
NSString * userCity = [fbLocation city];
NSString * userCountry = [fbLocation country];
NSString * userZip = [fbLocation zip];
You are currently accessing the name property of the FBGraphPlace which is giving you an NSString representation of the place. What you want to do instead is access the location property which is an FBGraphLocation. This object has properties for the various components you want.
But i'm not sure this is what you need.

Related

How to spoof different carriers in iOS?

Is it possible to spoof network providers just like it is possible to spoof locations in iOS?
I have an app that will get a user's ISO country code using Core Location, however I would like a fallback for when the user doesn't authorize location services for my app.
I have a function that is called in order to set a user's country according to their carrier; see below.
- (void)carrierBasedLocationSet {
if (DefaultCountryCode && ![DefaultCountryCode isEqualToString:#"Default"]) {
////NSLog(#"Skip Carrier Based Location set : DefaultCountryCode is [%#]", DefaultCountryCode);
return;
}
/***********************************
* Set country code based on Carrier
***********************************/
CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init];
Carrier = [networkInfo subscriberCellularProvider];
NSString *isoCountryCode = Carrier.isoCountryCode;
if (isoCountryCode == nil || isoCountryCode.length == 0) {
isoCountryCode = [[NSLocale currentLocale] objectForKey:NSLocaleCountryCode];
}
self.ISO_CountryCode = [isoCountryCode uppercaseString];
self.CarrierBased_ISO_Country = self.ISO_CountryCode;
}
This code works and produces US, which is where I am located. However, I want to test this out for different countries. Simply editing the product scheme to spoof a location in Australia, for example, does not give me back the AU country code and still gives me US.
Does anyone know if what I am trying to do is possible? Getting a user's location is essential to my application and I am unsure of another alternative.

How to retrieve an specific child in Firebase?

The childByAutoId would be useful if you want to save in a node multiple children of the same type, that way each children will have its own unique identifier.
pet:{
KJHBJJHB:{
name:fluffy,
owner:John Smith,
},
KhBHJBJjJ:{
name:fluffy,
owner:Jane Foster,
}
}
Therefore, once I have that uID, and I want to retrieve an specific user using the his/her uID. How do I tell Firebase that I want that specific user? Because I create it and store it in Firebase, but then to read it, don't I need to know the value of the uID? Where do I get it from?
What function do I use to retrieve for example the second user using the uID?
Thanks in advance..
in the title u ask how to get rid so:: get the new ref's key property to get the aid created
FIRDatabaseReference *ref = parent.childByAutoID
NSString *uid = ref.key
BUT thats not what you want id say, so:
to filter out all children where owner = XY which you want I think:
FIRDatabaseReference *ref = your pets node
FIRDatabaseQuery *allPets = [ref queryOrderedByChild:#"owner"];
FIRDatabaseQuery *specificPet = [allPets queryEqualToValue:#"XY"];
[specificPet observeEventType:FEventTypeChildAdded withBlock:^(FIRDataSnapshot *snapshot) {
NSDictionary *dict = snapshot.value;
NSString *key = snapshot.key;
NSLog(#"key = %# for child %#", key, dict);
}];
see: Query users by name or email address using Firebase (Swift)

Check if currentUser is the user that created the Post (iOS & Parse)

I want to check if the currentUser is the same as the user that created the post in order to display a button that would let the user delete that post.
I figured the best way would be to match the currentUser.objectId with the Post's "user Pointer<_User>".
I'm logging the currentUser's objectId with this code:
PFUser *currentUser = [PFUser currentUser];
NSString *currentUserID = currentUser.objectId;
NSLog(#"%#", currentUserID);
How can I log the Post's user Pointer<_User>?
Thanks.
First thing to do is to query the desired post object and then you can get the user pointer like retrieving the common value:
PFObject *post = ...; // I assume you know how to get your desired object
PFUser *postedUser = post[#"user"]; // user is the column name

NSString format issue - {( String )}

I am fetching data from core data and trying to print the name of the object at valueForKey. This has never caused me any trouble however when getting a direct object but the object I am getting is from an NSSet relationship.
When I print out the value I want, it displays in this format.
{(
Bob Marley
)}
{(
Jack Daniels
)}
etc...
I have used NSString stringWithFormat, I have tried componentsSeperatedByString, however neither of these work. If another question has been asked, I cannot find it on here. The issue is identical in a UILabel as well. Makes no difference where I print it.
Hopefully it's a simple issue.
My code for getting the value is.
//Company * company
//Employee is related in a many-many relationship
NSString * name = (NSString *)[self.company.contractor valueForKey:#"contractorName"];
NSLog(#"Name: %#", name);
Thanks.
self.company.contractor is NSArray.
So you need to do
NSString * name = (NSString *)[[[self.company.contractor allObjects] firstObject] valueForKey:#"contractorName"];
Also refer to my previous answer

Retrieve string from Parse.com

I want to retrieve the current users string value on a specific column from the user class in Parse.com
I have tried this code:
NSString *columnString = [[[PFUser currentUser] objectForKey:#"columnKey"] stringValue];
This code logged an error saying "unrecognized selector sent to instance.."
What is the correct way to do this?
If your column datatype is String then try below snippet.
NSString *str_ColumnString = [NSString stringWithFormat:#"%#",[[PFUser currentUser]valueForKey:#"columnKey"]];

Resources