iOS CNContact access number value

Hello, I trying to get a phone number of iOS contacts library. On iOS usually I getter with
let contact = getContact(with value: “filter…”)
func contacts(value: String) -> CNContact {…}

on Android I cannot get the value.stringValue and I don’t see any other property to map this value.

Hello @guillodacosta!
Please clarify, what exactly you are trying to do?
Also, I got to mention that Android NDK has no access to the contacts, so maybe you are talking about a Multiplatform library, not a native one?

Thanks @Artyom.Degtyarev,
I fix the message first, is not on Android what I try to access to value.stringValue instead of I should have said “on shared layer (iOS implementation through kotlin) of my multiplatform project”.
Second I trying to get iOS phone contacts using the class CNContact of platform.Contacts.*. For access to a phone on iOS (swift) usually I use the value property (type: CNPhoneNumber) of each one contact (type: CNLabeledValue<CNPhoneNumber>) and next I use the stringValue property thats has the phone number value that I need.
But in kotlin (shared layer of my iOS implementation) using the respective library given for kotlin I cannot access to value property or another one that map my phone number value searched.
Instead of that, kotlin is given to me a string that I don’t know how manage.
I made this for know, while you people lets my know how to do better.

val phonePosition = this.indexOf("stringValue=") + 12
val lastPhonePosition = phonePosition + 14
return this.substring(phonePosition, lastPhonePosition).replace("\\D+","")

where this is my phoneNumber value (which should not be like that)

And I believe that I did post this with a bad category, but I don’t know how update. Must be
Or I continue confuse with that is native and what is multiplatform :confused:

If you want to get phone number the same way as one can do in the Swift code, you can do it like this:

val contact: CNContact = CNContact()
val labeledValue: CNLabeledValue = contact.phoneNumbers()[0] as CNLabeledValue
val phoneNumber: CNPhoneNumber = labeledValue.value as CNPhoneNumber
val number: String = phoneNumber.stringValue()

This piece of code is incorrect as far as I do not initialize contact correctly, but the idea is to cast elements of the List, received from the phoneNumbers() function.
Also, to make it more clear with the native-multiplatform confusion. When we are talking about producing binaries from the Kotlin code - it is Kotlin/Native. And when we are sharing the common code between different products (JVM bytecode, binary files, JavaScript code) - it is Kotlin/Multiplatform.

1 Like