CNContact unique id between devices - ios

I'm having a bit of a problem with trying to access the same contact between multiple devices. My goal is to have a user select a contact and select a phone number and email address, which will then be stored in a database. If the user opens the app on another device, I would like to have the same contact selected.
I was hoping to use the CNContact.identifier for this case, but it appears that it is a device specific id. I could store the identifier for each device, but that would require the user matching contacts and that doesn't seam ideal.
This doesn't seam like it should be difficult but apparently I'm missing something. Thoughts?

The solution that seams to working for me is, I store the Contact identifiers, Address identifiers, Contact name, and the Address in my database. Then I take a mutli-step appoarch.
Search for Contact:
I attempt to find the contact based on the stored contact.identifiers I have already saved.
If I find 1 contact (identifier matched) => Great! I then attempt to match the found contact to my address.identifiers. Once again, if I find only 1 match, we're great! If not I then go to attempt to find an address (See below)
If I find no contacts (no identifiers matched) => I attempt to find the contact based on the Contact Name I had saved previously. If I do find a match, I then go to attempt to find the matching address (see below).
Search for Address:
Since at this point, I have a CNContact record that I believe matches, I look at each of their postalAddresses and compare it against the Street/city/state/zipcode/country that I have stored in my database.
If we find that perfect match, then I update my identifiers to include the new address/contact identifiers
If we ultimately don't find a match, I give the user an option to manually select the contact/address from their device.

Related

Can I remove the unique constrain for error "Asset/Device with such name already exists."

We are using open source Thingsboard for our IOT platform. One project has 100K devices/assets, and we have a tree structure for the assets/devices for example state -> county -> city, etc. Each county, we have an administrator who is responsible for asset/device creation. Frequently they use the same name for asset or device. Currently, Thingsboard doesn't allow duplicated name for asset/device. If we use the same name, we will get error messages
Asset with such name already exists
or
Device with such name already exists
We are thinking to remove this unique constrain but not sure if there is any side effect. Thanks.
It is not recommended to remove the unique constraint, but there may be workarounds:
Make the names unique, e.g. by concating the structure in the Tree for unique names (State_County_City_Device) or use the Device ID as name. In the Dashboards you can utilize the Label Field for a friendly-name.
See issue here: https://github.com/thingsboard/thingsboard/issues/4439

Firebase check for existing email with relative/wildcard path

Im trying to check the emails of my users in my firebase database, if their email already exists. My json looks like that:
I dont know how to get the full path to email, because every User starts with the Unique Identifier and I dont have that information. Is it possible to use a wildcard /users/*/email or something like that?
this.afdb.database.ref('users/*/email').orderByChild('email').on('value', (snapshot)=>{
console.log(snapshot);
});
When a Firebase Database query runs against a location, it considers each child node under that location. And for each child node you can test the value of properties at a known path under that child.
There is no support for wildcards, nor does one seem needed for your case here:
this.afdb.database.ref('users').orderByChild('email').equalTo("pqoo#poam.com").on('value', (snapshot)=>{
snapshot.forEach((child) => {
console.log(child.val());
});
});
So the two changes are:
We query location users order by email and only return nodes with value pqoo#poam.com.
There will potentially be multiple results. So the snapshot contains a list of those results. Even if there is only a single result, the snapshot will contain a list of one result. So we use snapshot.forEach(...) to loop over the results.

Take Action based on QR code Information of VCARD, iPhone

What is the best way to handle QR code's Information, As QR code can have any information, For now, I want to handle only
1 URL and redirect to safari browser--> its fine
2 vCard and open contact book with contact values, But I'm seeing that VCARDS keys name are not unique(not sure if I'm Having improper QR codes). And also, QR value is a string to how to detect which value is for which key of address book?
e.g:
"BEGIN:VCARD
FN:Ashwin kanjariya
TEL:+999-999-9999
EMAIL:you#we.com
URL:http://www.youandme.com
N:kanjariya;ashwin
ADR:any address
ROLE:software developer
VERSION:3.0
END:VCARD"
So, I'm Not sure for VCARD all keys are universal or not? What is the best way to handle it?
I appreciate your any kind of suggest that can help me to figure out VCARD parsing.
Is CFDataCreate with ABPersonCreatePeopleInSourceWithVCardRepresentation best way to go with?(I have support for below IOS 9 as well)
like
let vCardnsdata = CFDataCreate(nil, UnsafePointer<UInt8>(vCard.bytes), vCard.length)
let addressbookDefaultSrc = ABAddressBookCopyDefaultSource(addressBook)
let vCardPeople = ABPersonCreatePeopleInSourceWithVCardRepresentation(defaultSource.takeUnretainedValue(), vCardData).takeRetainedValue() as NSArray
VCARD has several versions with slightly different implementations, keys don't have to be unique, a person can have multiple home or work phone numbers for example, but you should be able to tell what is a phone number and just accept as many as your customer believes is reasonable for their use case.
An extensive list of what you may find in VCARD's is here: https://en.wikipedia.org/wiki/VCard
If you want to make sure that all the data is stored, then you may have to implement lists, or in database terms, store items in different tables so that one to many relationships can be maintained for several items.
When designing a system to store information about people, you may also want to observe some of the Falsehoods Programmers Believe About Names

ABAddressBook: Is it possible to fetch the name of the Source?

I'm developing an app that has to retrieve all the contacts from the Address Book and display them according to the source (Gmail, iCloud, Outlook, Facebook ecc). I've already looked up all similar previous answer on this topic: has anybody found an answer?
Is it possible to discriminate between these sources (for example using mail addresses)?
Using kABSourceTypeProperty and kABSourceNameProperty seems not effective because two Gmail accounts will have same name and same type.
Furthermore is there a way to have a more significant name?
For now I have only names like this:
- name = "" (empty string) for Facebook contacts
- name = "Card" for iCloud contacts
- name = "Address Book" for Gmail contacts
- name = nil for Local Address Book, etc
If someone else is still stuck with this problem i found a trick solution for the sources of type kABSourceTypeCardDAV (such as Gmail and Yahoo accounts).
The trick is to access the kABPersonLastNameProperty of the ABRecordRef of the source even if it should be a ABPerson-only property. The result is a path (I think where the contacts are stored in the phone) that contains also the mail/name of the account.
Still no idea how to get the name of the account in the kABSourceTypeExchange case!

not getting any address id from Quickbooks Online when I query customers

When I query for customers I get back a customer object with all the info. one of the properties is the Address. this contains the billing and shipping addresses for the customer. however, the id field for each address is always null. I am wondering how I push an update back to QBO without the id? how does QBO know which address I am changing without a key of some kind? my goal is to be able to query QBO and get all the customers and address that have changed since a specified date. I have all this working for the customer but need to do the same for addresses. I am going by the assumption that when an address is changed in QBO that is sets the modified timestamp for that customer record. can anyone tell me how I manage the addresses for a customer and be able to push updates back to QBO?
Try using tag(Billing/Shipping) attribute while updating the address. I've tested the same and it is working fine.
You mentioned earlier that you were getting the id field of address as null. It is becuase, the devkit works with both - QBO and QBD. QBD returns valid element id but QBO doesn't. So for QBO, Devkit shows null in place of element id(in your case - address's id).
You can test all these using api explorer(http://developer.intuit.com/apiexplorer).
Hope it will solve your porb.
Thanks
'the id field for each address is always null' - this line is not very clear to me. Did you mean the id of the customer entity ? Plz explain.
You can check the QBO-Customer object's documentation and sample update request xml, from the following Link - https://ipp.developer.intuit.com/0010_Intuit_Partner_Platform/0050_Data_Services/0400_QuickBooks_Online/Customer .
For testing you can use the api-explorer. Link - developer.intuit.com/apiexplorer
Thanks
Manas

Resources