Pergunta

I'm working on an iOS Cocoa app that has a fallback - if the user doesn't enter a certain piece of data, the device's UDID is used instead, as a default. I need to add a check in our server code (written in Ruby) to recognize whether the value being sent up is a UDID (the user's default) or a custom string that they've set.

It seems that the right solution to my problem is a regular expression. I'm comfortable writing regex'es, but I need to be certain that this regex is 100% guaranteed to recognize a UDID.

I retrieve the UDID in code using:

[[UIDevice currentDevice] uniqueIdentifier]

And in the simulator, I get back this value:

6938CA7D-ECE2-53A4-B293-961A8D07AFB1

From this I might infer that I can just search for a string of hex characters that matches the pattern 8-4-4-4-12. But I want to be certain this works for every UDID.

I can't find anything about this in Apple's documentation and was wondering if anyone could give me a definitive answer to this question... thanks!

Foi útil?

Solução

Why not send another bit of data indicating that it is a UDID? Or just use a different parameter name (UDID=6938...).

Then, in your server, you can test it like so if you really want to:

# somewhere outside the controller action, maybe the top of the file
UDID_PATTERN = /\A[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}\Z/

# inside the controller action you're sending info to
udid = params[:UDID]
if udid && (udid =~ UDID_PATTERN)
  # do something with the UDID in place of the other
  # bit of info they could have provided
end

Outras dicas

Obviously, the only guaranteed way is adding additional field which marks whether your user entered expected data or not.

UDID form and algorithm is not published, and not designed to be detected again. So determining might be possible, but it never be 100%.

You can't tell. Apple's documentation says:

A device’s unique identifier (sometimes abbreviated as UDID for Unique Device Identifier) is a hash value composed from various hardware identifiers such as the device serial number.

The iPhone simulator returns a different value for the uniqueIdentifier compared to real iOS devices. All of the real iPhone devices I've used have UDIDs that are 40 hex characters. But it's best not to make any assumptions.

Even if there were a UDID pattern, what if the user entered something that matched that pattern?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top