Is there a way to extract user’s full name from HealthKit in Swift? - ios

I am trying to build a fitness app and I would like to build the user’s profile within the app but I would like to make it as quick and easy as possible for the user. I am able to extract the users stats such as height, body mass, birth date etc from HealthKit but is there a way for me to extract the user’s full name since the ios health app has this on it’s profile page.
I have sifted through the documentation, but so far I haven’t found anything.

no there is no api AFAIC.
you can ask for addressbook access and read the 'me' contact

Well you could go through all the contacts in the AddressBook and see if any of them are marked with the owner flag.
Just be aware that doing this will popup the "this app wants access to the address book" message. Also Apple isn't very keen on these kind of things. In the app review guide it is specified that an app can not use personal information without the user's permission.
You will get the username like this:
var username = NSUserName()!
and you can use same user name for your app.

Yeah, I don’t want to meddle with the address book and freak the user out. I’ll probably just ask them to enter their name instead.

Related

How do apps access your username / device name without the user explicitly providing it? (Example in description)

For example, the VLC app was able to somehow get my username (or device name?) without me ever giving it this info. Here is a screenshot that shows the VLC app greeting me by name in the app switcher. How is this possible if I never gave the app this information? Which API could it be using to obtain this info?
This is possible due to UIDevice class. It doesn't require permissions in order to get some basic system information, after all it's just your name (if you were to ask for location/health data/contacts/etc that would be something else and thus user permission is mandatory).
For more information refer to official documentation here https://developer.apple.com/documentation/uikit/uidevice
That's not VLC but rather iOS.
iOS suggests apps based on time and location of your device. The name is taken from your iCloud Account. VLC is not aware of that banner.

Requesting data about user iOS

Is there an API in iOS which would allow me to discover information about the user who owns the phone?
The address book api would allow me access to their contacts, but how would I find out about the self user?
Thanks!
You could go through all the contacts in the Address Book and see if any of them are marked with the owner flag.
Edit
This was removed a while back, another way is getting the device name
UIDevice.currentDevice().name
"Bob's Iphone"
Then you could cylce through the address book and find a bob, this is a solution i wouldn't recommend, the best bet might be to ask the user for their details
Well there's not much more you can get from a user due to them wanting their privacy but there are a couple of things you can still find out about a user:
Get Device Info (find out more about their device)
HealthKit API (Get users health data like how many steps they make what they eat and drink etc)
Photo Album Access (access to their photos and videos)
That's about it really! Hope it helps :)

Is there a way to access the user's own address book data (first & last name, e-mail) in iOS?

I want to prefill some input fields in an app's registration process in order to make it more seamless. Is there a (Apple authorized) way to access this data?
Thanks,
Georg
No, what you want to do is an often requested feature, but for reasons unknown (probably security related) there is no way to even determine if the phone's owner has an address book entry. I suggest you go to bugreporter.apple.com and ask for this feature (as many of us already have!)
I think you need to pre fill the values from your device's address books. If so you have to dig your head into AddressBook Framework in order to access the contact details. Below link is from iOS developer link
http://developer.apple.com/library/ios/#documentation/AddressBookUI/Reference/AddressBookUI_Framework/_index.html
http://developer.apple.com/library/ios/#documentation/AddressBook/Reference/AddressBook_iPhoneOS_Framework/_index.html#//apple_ref/doc/uid/TP40007212

Inviting users to an IOS app

After registration, our app prompts users to invite her friends (aka phone contacts) to use the app too. This allows us to send an email/sms to the useer's contacts with some sort of invitation key. Works fine for a web version app, just embed the key in the url you provide in the invitation.
I'm having trouble figuring out how to make this work smoothly with IOS only. It would be brilliant if I could send the invitee a link to appstore.apple.com/myapp?registrationKey=abcXYZ and have the key magically available to my app once it's installed, but I guess this is a lot to hope for?
The obvious way around this is to make the user manually enter their registration key on first launch, but this seems less reliable and (to my mind) adds friction to the UX.
Has anybody come up with something clever to get around this?
Here is what is flowing through my brain on how to solve this solution, please note, I have not vetted, psudeo-coded, coded, or applied this theory.
Since you will know who is being sent an invitation, save that data to your database with a relationship to the user sending and a unique id to the user being invited (email address if its in the contact's card). When new users sign up scan the database for invitations, if one is found present it to the user asking We're you referred by <existing user>? Once the new user selects their response continue through the registration process, updating the relationship table accordingly and applying any extra settings you need to for the referral.
This combines automatic referral tracking with referral codes for a basic, straight-forward, almost (but not quite) fool proof method to make sure referrals are linked to the right users.
As far as I can tell, the App Store provides an information firewall between an invitation and the installed app.
The closest workaround I've seen is the following:
email link sends you to your website
the website logs reference information in the URL and the IP address
the website instantly redirects you to the App Store (if iOS detected)
user installs the app
user loads the app
app contacts your website, IP addresses matched ... BINGO
Obviously not a secure method though.
There are many failure cases:
business networks commonly share IPs
home and mobile networks release and reuse IPs
The more is frequently used to resolve cases where its good enough to know that the user 'almost-certainly' was referred to download app by the email.
For example, it can be a good mechanism to prompt the user with a "who do you know" question in an app and limit the options based on the (IP+reference) data. If they pick the original poster, then maybe that's good enough, and then you can attach any other data that the inviter provided.
(Full disclosure, currently work at Branch)
The best solution to this is to fingerprint a user. This requires you to do the following steps:
For each user, using your own domain, generate a link for said user. So, right when they complete registration, generate their unique URL, that contains the invitation key.
For anyone clicking this link, they will redirect to Safari first. When they do, capture their IP address and iOS operating system version from the headers and user-agent.
Save this data on your server, and set window.location to your iTunes url.
If the user downloads and consequently opens, inside AppDelegate.m, send a message to your server with the IP address + major/minor/min version you collect upon app launch. If it matches with what you have on the server, you can now pass that invitation key back to the new user.
It's not perfect, and has the ability to misattribute. You could also use branch.io, where all of this is taken care of (link-generation, fingerprinting a user, attribution). Branch also drops a first party cookie and ties it with the device level ID, so attributions are much more accurate.

Track location of friends

I would like to make it possible for the user to track their friends through one of my applications. The application is for a music festival.
I have been thinking of ways to do this:
Let the user set a nickname for the device (associated with the UDID) and let users add each other to a "friend list" by their nickname. When the application is running the location of the users would be sent around through push messages. This might be a bit hard to integrate - and I kind of hate working with push notifications.
Set up accounts for each user then store the user's most recent location in a database and read them. Again, users will add each other by nicknames. This would be a really easy solution but I am not sure if it is legal to store the location of the user (maybe I could ask them for permission and not have this option enabled by default?)
I have seen an application doing this "friend tracking" and doing it by having the user log into Facebook. I did not try this feature and I do not know how they do it with Facebook. Maybe you do?
Any thoughts on these solutions or are there any other ways to accomplish this?
Have you seen google latitude?
http://nexos.ravex.net.au/apps/xnetViewer/?q=google+latitude
Has api
http://code.google.com/apis/latitude/

Resources