Can CloudKit user phone numbers be retrieved using `CKDiscoverAllUserIdentitiesOperation`? - ios

Background
I am retrieving all the users for my app using the recommended CloudKit operation, CKDiscoverAllUserIdentitiesOperation.
This operation is designed to returns each user's info in a CKUserIdentity object. The lookupInfo attribute of the user identity has fields that can contain the user's email address and the user's phone number.
e.g.
user.lookupInfo.phoneNumber
user.lookupInfo.emailAddress
Question
When I run this operation, I only ever get each user's email address. The phoneNumber field is never populated.
How do I retrieve these user identities and have them include the user's phone number? (Is this possible?)
Additional Info
I am able to retrieve individual users with their phone numbers using the discoverUserIdentity(withPhoneNumber... CloudKit function, so I know that these accounts are linked to phone numbers.

All you get is the email. That's it. It's not possible to get any more info than that using CKDiscoverAllUserIdentitiesOperation. And that is only for users that have agreed to be looked up via email while using your app.
The only time the phone number is filled in is if you specifically lookup the user by phone number. Of course that's kind of pointless since you already know the phone number.

Related

CloudKit: can't discover identities

Pretty new to CloudKit. Trying to get all the contacts who are using my app. According to the docs and the tutorials out there I'm calling this:
discoverAllIdentities(completionHandler:)
The issue is that only my user (the one who is logged in on the device where the app is running) is returned. So I did some digging and noticed that if I call this one:
discoverUserIdentity(withPhoneNumber:completionHandler:)
and I use phone number directly the user is returned.
So after more investigation, I figured that the reason I do not get those users is that in my Contacts those users do not have their iCloud email stored. So once I add the email, they are returned by discoverAllIdentities(completionHandler:). So it appears the default implementation of that method is tied to iCloud emails for the discovery instead of phone number.
Is it possible to use phone number for discoverAllIdentities(completionHandler:)? Since, I don't think that as you add a new contact you would record anything but just phone number, so you will be missing to discover all those users.
Any kind of help is highly appreciated.

Recovering contact info of the current user

I'm having trouble searching online for this and I've missed it in the reference materials if it's there.
I'm writing an iOS app in Swift, and there are participants in the app whose contact info can currently be saved into the user's address book, using the Contacts Framework.
What I'd like to do is when the user has to save their own participant information into the system, I'd like to present their default contact info from the address book as the text fields' default text. I figured this would be possible using the contacts framework, but I'm not sure how to fetch the current user's information.
Does the contacts framework even keep track of that? I thought it did, because the Contacts app has my own phone number at the top of it's listings, but I realized afterwards that it's just the device's number, not a whole contact file. If so, do I search for it with a specific predicate or is their a function I can call?

IOS: How to verify user's phone number using codes

i am working on an app in which i take a field of mobile number of user after entering mobile number there is a option for verify phone number.
but i don't know the functionality of how to verify a user's phone number within the app using codes.I search for similar type of questions but didn't get the exact solutions.
i am sending a screenshot of my app where i want to put that functionality.
i didn't apply any codes for this
please help
You need a backend that can generate and save codes for each phone number and also send a text message with those codes. So the flow is as follows:
User enters their phone number in the app and presses the "Verify Number" button.
You send a request to your backend with the number provided. In the app, you also displays a text field for user to enter the generated code and a new button like "Check code".
The backend generates a new code (just a random one), stores it to the database (like ID,PhoneNumber,GeneratedCode,DateOfGeneration) and sends a text message with the code to the phone number specified.
When the user receives the message he or she enters the code to the checking input field and presses the "Check" button.
The mobile app sends another request to the backend with the phone number entered earlier and the code entered by the user now.
The backend looks to the database for the "Phone number" - "Code" pair and responds with failure (the code is incorrect, try again) or success (the phone is verified).
Unfortunately, there's no way to access text messages received by user from within an app on iOS devices (unlike Android). The proof link was already provided. So the user has to manually enter the verification code from the message.
Ok I tell the information how was I already did my project in before
Step-1
when user press the Verify Number button
initially I check the phone number is valid or not(means phone number count/length).
second I generate the random number on progrmatically like NSUInteger r = arc4random_uniform(16);
Step-2
send the random number to server along with the vaild phone number , the server send the random number to the particular mobile number using SMTP Server.
Step-3
in your hand you have the random number , so open the UIAlertview for user type the valid random number , if user typed the vaild number show the Next Screen else show the Alert.
To verify any mobile number you can use third party api's which are available for mobile as well as backend server. You can use Twilio Messaging Api. To use this API follow below steps:
Register account on Twilio and get key from account.
Get user's phone number from mobile application.
When user click on the "Verify Number" button, call web-service with the number.
When you'll call the web-service, write a logic to send the random number with the Twilio messaging api to send message to user.
When user get this number through SMS, You can tell user to enter the number and verify it.
Also, there is another api which you can directly integrate into your mobile application. You can find this Sinch Api here.
To verify against your device's phone number, first, you need to get the phone number from your device and then you can compare against. However, after iOS 4, getting phone number of your device is quite impossible. Even if, you do get the device's number using some private api which I am not sure works entirely, there is a huge possibility for Apple to reject your app.
Refer to the following stack overflow discussion-
Programmatically get own phone number in iOS
Just a suggestion: You probably want to look for a work around based on your business goal. For example, rather than checking for device's phone number directly. You can generate a code and send that to the number specified by the user and then enter that code to verify that the user has that device.

How does snapchat do their friends functionality?

So I am trying to have users in my app find each other via their address book (a la Snapchat). How do I go about this?
I can have access to the user's address book so I would be able to associate each number with a user (I verify this via text for each user). Once I have all these users associated though, would I have to compare each phone number to my data base (Parse) in order to have a section of "Friends who have MyApp"? Otherwise, how can I grab an address book of X user and tell them which of his contacts have the App already installed?
Also, I have read in many places I should not upload their contacts info to my backend.
Help?
First thing that comes to my mind is to store each user's phone number as well. However, you might be right about not to upload their contacts to your server even though you do ask for confirmation that you're going to access their contact list.
I'll put forward another idea, how about storing their contact list as encrypted data? Thus, even you personally won't be able to reach any of the contact info. Use an irreversible encryption algorithm like sha512 and then store these phone numbers as encrypted strings. Each time a user requests if his/her contacts are exist in your database, encrypt each phone number locally and make a request if those strings exist in your DB. This implementation is really similar to common password storing techniques and I believe it is quite secure -and ethical.
Related: How can I compute a SHA-2 (ideally SHA 256 or SHA 512) hash in iOS?

Identify email id configured in email app in ios device

i have requirement where in my app i can send some data as attachment via email to people in my contact. when the user opens attachment, it opens with the help of my app and saves the data in the receiver's app's database. also actions assigned to that person gets saved in his device's calendar as an event. the problem is that i will be sending the data to multiple recipients and action tasks assigned to everyone, so i need to know the receiving person's identity to save only task assigned to him in his device's calendar as event. now the requirement given to me is when creating action task for each person i also need to save his email-id[as person is selected from contacts stored in that device], so if i can find the receiver's email id i can identify tasks assigned to only him and save to his calendar.
As This is not possible to get Configured Email details in iOS Device (in Non Jailbroken device, no idea with Jail broken device) it breaks user privacy.

Resources