7

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?

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Roger
  • 73
  • 2
  • 12
  • 1
    possible duplicate of [How do you get an iPhone's device name](http://stackoverflow.com/questions/1100127/how-do-you-get-an-iphones-device-name) – rintaro Feb 19 '15 at 02:41
  • What you are trying to get is "device" name, not "user" name. – rintaro Feb 19 '15 at 02:42
  • 1
    This may look weird. My iPhone's name (and probably everyone's) is Linus' iPhone. So your app will say "Good morning Linus' iPhone". I don't know if that's so awesome… – LinusGeffarth Jun 05 '17 at 06:30
  • Does this answer your question? [Better way to get the user's name from device?](https://stackoverflow.com/questions/8261961/better-way-to-get-the-users-name-from-device) – Troy Dec 20 '21 at 16:40

3 Answers3

3

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

ingconti
  • 10,876
  • 3
  • 61
  • 48
2

Swift 2
UIDevice.currentDevice().name
Swift 3
UIDevice.current.name

Dylan
  • 1,071
  • 1
  • 12
  • 24
-1
let benutzerGeraeteName = UIDevice.current.name
        print("Hallo, \(benutzerGeraeteName)")
Steffen
  • 161
  • 1
  • 5