Any way to get the name of iPhone user?

后端 未结 5 1180
醉梦人生
醉梦人生 2020-12-28 17:46

Outside of asking the user to input their name, is there any way to get it off the device?

I tried this library, which attempts to extract the name from [UIDev

5条回答
  •  Happy的楠姐
    2020-12-28 18:10

    You can use:

    NSLog(@"user == %@",[[[NSHost currentHost] names] objectAtIndex:0]);
    

    I did receive compiler warnings that the methods +currentHost and -names were not found. Given the warning, I’m not sure of Apple’s intention to make this available (or not) as a publicly accessible API, however, everything seemed to work as expected without the need to include any additional header files or linking in additional libraries/frameworks.

    Edit 1: You may also take a look at this Link

    Edit 2: If you have integrated your app with Facebook you can easily retrieve the user info, see Facebook Fetch User Data

提交回复
热议问题