I'm trying to create an app that when the user open the first view it will provide with a nice greeting.
For example depending on the time of the day it would say "Good Morning/Afternoon/Night - User Name".
How do I get the name that the User has on his iPhone? I need the name that is on Settings > General > About _ NAME
?
Swift 2
UIDevice.currentDevice().name
Swift 3
UIDevice.current.name
UIDevice.current.name gives back device name, so you should parse the string trying to distinguish between device type (iPhone, iPad and so on...) and the name. But is bit tricky: suppose You have "My iPhone" , "Mary's iPhone" or "IPhone of John" or similar.
Soem people try to use regular expressions, but result is not so good, specially for non-english names. see at:
http://stackoverflow.com/questions/8261961/better-way-to-get-the-users-name-from-device
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With