I am building an application that I will need to distinguish the Google Contacts from each other. I am just wondering, as long as google sends contacts as First Name/Last Name/mail.. etc (Example) without a unique ID, what will be the first approach to distinguish each contacts?
1) Should I create an ID based on the user's fields? -> by a minimal change, it can break down.
2) Should I create an ID based on First Name + Last Name? -> but most people can have duplicate contacts on their page, would that be a problem? Or married contacts, which can create a little mess.
The reason I am asking this I am trying to create relations and I need to store the data somewhere like that [person=Darth Vader, subject=Luke Skywalker, type=father(or son)], so I need a fast algorithm that can make a mapping for each contact and retrieve the related contacts fast.
I believe they do send back an ID. From the return schema:
<link rel='self' type='application/atom+xml' href='https://www.google.com/m8/feeds/contacts/userEmail/full/contactId'/>
You could use the full HREF value as the ID, or parse out the contactID from the end of the URL, whichever you like better.
Related
I am currently setting up my realtime firebase database to my iOS application.
It is my first time trying to structure user data in a firebase database, and I am really, really struggling with understanding a few key things.
A bit of context to my application's database needs:
When a new user is created, the attributes assigned directly to the user are:
Age
Email
Username
Nationality
Later on, the user needs the option of creating personal diaries!
Each of these diaries being arrays/lists of objects... Where each object in a diary furthermore holds a few attributes in a list/array.
After reading everything I could find anywhere, I picture my database something like this:
I am terribly sorry if it becomes too specific - I will try to make the question as open as possible:
My question is:
How to create the different "children" programmatically and how to find the keys leading back to them, so I can refer to them at other times again? (when editing an attribute in a child).
A few methods I have tried:
setValue([ArrayOfObjects]) --> This creates the desired array, but I can't seem to find e.g. index 3 in this array, to allow user to change his/her email later on.
childByAutoID() --> This as well creates my array, but gives several other problems: User can only store one diary, still can't find the paths to specific indexes...
setValue(), andPriority() --> Can't seem to make the priority function. (Is this function also outdated??)
And a few more...
If anyone can tell me how to achieve just the first few steps in setting up my database structure, I will be forever grateful - I have spent literally all day on it and I am not moving forward ...
Or, at least tell me, if I am on the right track regarding my desired setup of the database. Is it flat enough? Is there a smarter way to store all these user created lists?
Thank you so much! :-)
I don't know Swift so my examples are in Dart but the methods are similar I believe.
First off, I would split the Users node into two. One to hold the user data, which is normally pretty static, and the other to hold the diaries. You would use the same uid key as reference to both. This way you have less nesting to worry about and therefore it is much easier to CRUD the data. If you are using Firebase to authenticate your users then I would use the unique key that Firebase creates for each user as the keys for these two nodes.
Then...
To create a user data node record the Dart code would be something like:
referenceUserData.child(<authenticated user id>).set({
"age": <age value>,
"email": <email value>,
"name": <name value>,
});
To create a user diary node object record the Dart code would be something like:
referenceUserData.child(<authenticated user id>).child(<diary key>).child(<diary object key>).set({
"object info value 1": <object value>,
"object info value 2": <object value>,
"object info value 3": <object value>,
});
You could also create all the object records at once by writing them as a List (array) using .set().
You also need to decide what your diary key should be. You could use Firebase to generate a unique key by using .push().set().
To read eg. the user data then your call could be:
referenceUserData
.child(<authenticated user id>)
.once()
.then(
(DataSnapshot snapshot) {
print(snapshot.key);
if (snapshot.value != null) {
print(snapshot.value);
<code to process your snapshot value>
}
};
BTW, 'priority' is legacy from the early days of Firebase RTDB so I wouldn't try to use it.
I work on iOS app that use firebase real time database, my structure as , I want to write a query that retrieve all users of a group, each user have multiple groups, and each groups have multiple users, I capable of showing all groups of one user and I want to show all other users they are belong to that group, i.e, when user choose of his groups,
How can achieve that?
In my opinion, the best way to deal with this is to duplicate your data. If you definitely need the structure you posted above, you can keep it and create also another one as such:
"groupUsers": {
"123" : { //groupId
"235" : { //uniqueKey for record
userId: "567",
userName: "Jack"
}
}
}
To get all users in a certain group use the firebase reference:
`/groupUsers/${groupId}/`
You loop over the returned list to show values from each list item.
What would be the best way to uniquely identify an MSConversation when developing an iMessages application?
In my case I want to give to a game object an ID of the conversation where it belongs to.
Take the localParticipant ID, add to it the remoteParticipants ID ;)
Something like that :
var conversationID = yourConversation.localParticipantIdentifier
for participant in yourConversation.remoteParticipantIdentifiers {
conversationID += participant
}
EDIT:
As noticed in comments, by doing so, you could end up with a very long ID. So the idea is to apply an hash to it, to have a constant size (MD5 is suffisant, we don't need something secure here). If it is still too long, you could crop that hash, but be aware that in that case there is a small probability for two conversations to have the same ID (depending on how much your crop).
The current top answer has a corruption issue in that if a new person is added to a group chat (or if someone is removed) your hashed ID will change.
A more elegant solution in my opinion is to just create your own serial number at the time of the first message being created and add it as meta-data to your message itself. (Using NSURLComponents of course). Then just grab that anytime a message is opened (thus launching your message app) and use that ID. Just keep it in the header of any message sent/received.
But, it depends on what you are trying to do really. The solution I've provided is great for turn-based multi-player games. It might not be good for other scenarios.
I have a firebase database which I have imported a list of approx. 8200 Universities with the details seen above.
I want to be able to enter an email address into a text field then query the "domain" part of this JSON. My issue is I need to query all the domains in the list of 8000, however I do not know how to search domain ad I do not have the "7542" to use a childByAppendingPath.
So I have a reference to "universities" but I need to be able to query "domain" without knowing the parent key (i.e. 7542 in the example above, but I want to search the domain, "iautb.ac.ir").
You need to create a reference and Query that reference, check this link to find more about how to retrieve data from firebase.
Basically you need to do something like this
let myRef = Firebase(url: "https://your.firebaseio.com/universities")
let query = myRef.queryOrderedByChild("domain").queryEqualToValue("yourDomainSearchValue")
and then observe the events you need to on your query
I am trying to obtain all related contacts to a selected contact. The way to do this seems to be via mycontact.contactRelations. This gives an array of CNLabeledValue with each of those containing a CNContactRelation as their value. There is then a name property, but it appears nothing else.
The Xamarin documentation for CNContact.ContractRelations seems to suggest I should be able to obtain the corresponding CNContact from a CNContactRelation but I can see no way to do this in objc, other than searching for a contact with a matching name. This may or may not be the contact I'm after, even if they also have a relationship to a contact with the same name as mycontact.
The identifier on the CNLabeledValue seems to refer to the label rather than the related contact, or at least doesn't seem to match the identifier if I select that contact from a CNContactPickerViewController.
Is there a way to obtain the CNContact for the related contact in objc ?
The related names field in Contacts doesn't store linkages, just names. You'll notice this from a user perspective if you go to edit related names in the iOS or OS X Contacts app — it's just a freeform text field. Those apps (and other system apps) will recognize when a related name matches that of another contact (which is why you can ask Siri to call your mother, etc), but they also let you put down names for people you don't have contact info for.
So a CNContactRelation just contains a string, and the only way to find (if there are any) contacts matching a related name is to search the contact store. Use unifiedContactsMatchingPredicate:keysToFetch:error: to search, with a predicate constructed by calling predicateForContactsMatchingName:.