How to create contacts list like whats app did

左心房为你撑大大i 提交于 2019-12-13 03:01:39

问题


I'm working on an app that creates an user profile. I need to be able to see who from my contacts has the app installed so that i am able to grant them access to my profile and see their profiles.

How do i get the full contact list, determine my phone number to create my account with it, and check how many people from the contacts have the app installed? (similar to how WhatsApp does it)

I know it's possible to get the contact list by using Apple API's, but do i have to send all the information to the server to check if they have the app installed?

Thank you.


回答1:


I think you are managing one local database to store users locally.

First, You must have one contact mapping table on server that determines which number is allocate to which user (Each user must have unique number per account).

You have to pass array of phone numbers to your server request and fire query to get only those users whose phone numbers are in array.

You get one users objects array and that array you have to save in local database. (You can store all contacts in local database and update record (for appId, contactId, server name etc) is user is application user).

Finally these users who has appId are your application users.

Hope this concept might help you.




回答2:


If you are using webservices your backend will can give the contacts which are using your application.

For getting the app contacts you have to use user phone number using phone number you can get the app user through webservices




回答3:


to get all contact from Phonebook you can use below method in swift first import Contacts

 func FetchContact()
    {
        if #available(iOS 9.0, *) {
            let contactStore = CNContactStore()

            do {
                let request:CNContactFetchRequest
                request = CNContactFetchRequest(keysToFetch: [CNContactGivenNameKey, CNContactFamilyNameKey, CNContactMiddleNameKey, CNContactEmailAddressesKey,CNContactPhoneNumbersKey])
                request.sortOrder = CNContactSortOrder.GivenName
                try contactStore.enumerateContactsWithFetchRequest(request) {
                    (contact, cursor) -> Void in
                     self.dataArray?.addObject(contact)
                }
            }
            catch{
                print("Handle the error please")
            }
            //self.collectionView?.reloadData()
        }
    }


来源:https://stackoverflow.com/questions/34591495/how-to-create-contacts-list-like-whats-app-did

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!