问题
Is it possible to retrieve the user email associated with the default email account directly from an app?
Screenshot:
Thanks.
回答1:
I can't prove a negative, but I am fairly certain this is not possible. You can use MFMailComposeViewController to allow the user to send an email from the default account, but you cannot directly access information about the default account. If you need the user's email address, you either have to ask for them to type it in, or have them select it from their contacts.
回答2:
In addition to @woz answer, this is a gist that can help you.
In my app, I have a feedback form to let users could get in touch with me. Unfortunately, many users had minor misspellings in their email addresses and I couldn't reach back to them.
As I couldn't get a perfect way to be sure the email was correct, I've developed the following gist which:
- asserts the mail is a proper foo@bar.tld
- verifies that the email is contained in the user's address book
- if not, suggests the closest match
Again, this is far from perfect and I only included this behavior optionally (a little 'check mail' button next to the UITextField)
https://gist.github.com/dirtyhenry/7547064
来源:https://stackoverflow.com/questions/10758431/get-default-user-email-in-ios-device