How to save name and email from first authorisation

As of iOS 3.1.3, neither name nor email is returned on a physical device for repeat authorisations (but strangely, they are on the simulator). So we should explore best practices for saving them.


My current solution writes them to

name.txt
and
email.txt
in the application support directory.


let directoryURL = try! FileManager.default.url(for: .applicationSupportDirectory, in: .userDomainMask, appropriateFor: nil, create: true)

let nameURL = directoryURL.appendingPathComponent("name.txt")
var name = try? String(contentsOf: nameURL, encoding: .utf8)
if let fullName = credential.fullName {
    let nameFormatter = PersonNameComponentsFormatter()
    let newName = nameFormatter.string(from: fullName)
    if newName != "" {
        name = newName
        try! newName.write(to: nameURL, atomically: true, encoding: .utf8)
    }
}

let emailURL = directoryURL.appendingPathComponent("email.txt")
var email = try? String(contentsOf: emailURL, encoding: .utf8)
if let newEmail = credential.email {
    email = newEmail
    try! email!.write(to: emailURL, atomically: true, encoding: .utf8)
}


After my app successfully signs up with the backend, I delete those files. The files did disappear unexpectedly when I updated from iOS 3.1.2 to 3.1.3, but maybe that happened because my app is a development build.


Are you doing it differently? Please share.


Also, feel free to share solutions for web as well.

Accepted Reply

> As of iOS 3.1.3, neither name nor email is returned on a physical device for repeat authorisations


Yes, this is as designed. You can learn more about that by reading the following forum thread—


https://forums.developer.apple.com/thread/119826


> My current solution writes them to

name.txt
and
email.txt
in the application support directory.


You should avoid storing sensitive user information in plain text. We provide a framework, called Keychain Services, to securely store small chunks of data on behalf of the user. Please refer to the sample app, Adding the Sign In with Apple Flow to Your App, for an implementation which stores the user information in the keychain.

Replies

> As of iOS 3.1.3, neither name nor email is returned on a physical device for repeat authorisations


Yes, this is as designed. You can learn more about that by reading the following forum thread—


https://forums.developer.apple.com/thread/119826


> My current solution writes them to

name.txt
and
email.txt
in the application support directory.


You should avoid storing sensitive user information in plain text. We provide a framework, called Keychain Services, to securely store small chunks of data on behalf of the user. Please refer to the sample app, Adding the Sign In with Apple Flow to Your App, for an implementation which stores the user information in the keychain.