Search code examples
iosswiftimessage-extension

iMessage current user's name is nil


I am creating iMessage application. My problem is that I do not know how to get the current user's name.

I tried like this:

"\(conversation.selectedMessage?.senderParticipantIdentifier.uuidString) Sent You A Challenge"

And like that:

"\(conversation.localParticipantIdentifier.uuidString) Sent You A Challenge"

But both of those are "nil". Is it the right way to get the username?


Solution

  • I missed the "$" sign prefixing.

    To get the name of the local user: $\(conversation.localParticipantIdentifier.uuidString)

    WARNING!

    If you try to print it, it is simply UUID without the name. The thing is that Message app will replace them with the contact’s actual name before showing them to the user.