SpaceDog SpaceDog - 4 months ago 80
iOS Question

Strange Thing Going on with UUID on messages extension

I am creating this messages extension that is a game.

When I receive a conversation on

I grab my UUID and the opponent's UUID, for example:

myUUID = [conversation.localParticipantIdentifier UUIDString];
opponentUUID = [[conversation.remoteParticipantIdentifiers firstObject] UUIDString];

at this point if I print this I get something like

myUUID = 3A00236E-606E-41BE-BD11-97658AF13434
opponentUUID = 794DC7EB-E0AF-46CD-9BF0-5B6D39CC6773

Then I make my move in the game and send to the opponent.

On the simulator I switch from "Kate" to "John Appleseed".

When the method
triggers again, now for the other user, I grab both UUID again. This is the result:

myUUID = 3A00236E-606E-41BE-BD11-97658AF13434
opponentUUID = B4621E05-4407-443E-9526-C8F0C82753D6

What? myUUID is the same as before and my opponentUUID is completely different?? By switching users on message I was expecting to see the entries reverted. How can that be? Bug?


Apple doesn't like issuing numbers that can be used to identify users beyond what is strictly necessary. In this case, the localParticipantIdentifier property is unique to each device (so person A has different identifiers on each device they are talking with) and each app install (so two different apps will see two different identifiers).

In fact, if the user deletes and reinstalls your extension, the identifier will be changed – just like identifierForVendor on UIDevice.

From the docs:

This UUID is scoped to this device. It remains stable as long as the extension is enabled. If the extension is disabled and reenabled, or if the containing app is removed and reinstalled, the UUID for the local participant changes.

This particular case is complicated by the fact that you're using the simulator, which is rigged by Apple to look like two accounts even though it's one device. I suspect that when you run the same code on two real devices you'll find two completely different numbers on both sides.

It's worth adding that there are several open radars for Messages identifiers, not least this one, so you might be right that it's a bug.