0

In My app I am using Sign In with Apple option. Here I face an issue with users who done sign up Apple ID with phone number. I wanted to send a notification to user regarding the events which is upcoming which is available on back end.

Here is my code how I do authentication

    let provider = ASAuthorizationAppleIDProvider()
    let request = provider.createRequest()
    request.requestedScopes = [.email, .fullName]
    let controller = ASAuthorizationController(authorizationRequests: [request])
    controller.delegate = self
    controller.presentationContextProvider = self
    controller.performRequests()

and the deligate to grab the details

func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
    switch authorization.credential {
    case let credentials as ASAuthorizationAppleIDCredential:
        let userIdentifier = credentials.user
        var firstName = credentials.fullName?.givenName
        if (firstName?.count == 0) {
            firstName = KeychainItem.currentUserFirstName
        }
        var lastName = credentials.fullName?.familyName
        if (lastName?.count == 0) {
            lastName = KeychainItem.currentUserLastName
        }
        var email = credentials.email
        if (email?.count == 0) {
            email = KeychainItem.currentUserEmail
        }
        self.saveEmailInKeychain(email ?? "")
        self.saveFirstNameInKeychain(firstName ?? "")
        self.saveLastNameInKeychain(lastName ?? "")
        self.saveUserInKeychain(userIdentifier)
        var param: [String: Any] = ["social_login_id" : userIdentifier, "provider":"apple"]
        if (firstName?.count ?? 0 > 0) {
            param.updateValue(firstName ?? "", forKey: "first_name")
        }
        if (lastName?.count ?? 0 > 0) {
            param.updateValue(lastName ?? "", forKey: "last_name")
        }
        if (email?.count ?? 0 > 0) {
            param.updateValue(email ?? "", forKey: "email")
        }
        appleSignInParam = param
        break
    default:
        break
    }
}

private func saveUserInKeychain(_ userIdentifier: String) {
    do {
        try KeychainItem(service: "com.XXXXX", account: "userIdentifier").saveItem(userIdentifier)
    } catch {
        print("Unable to save userIdentifier to keychain.")
    }
}

The problem I face here is if user have created Apple ID with phone number I have not contact with the user. Is there a way to communicate with user if they have used their Apple ID as phone number.

Thanks in advance

AJ Sanjay
  • 1,276
  • 1
  • 12
  • 29
  • The user may decline to share their email with you. You can ask them to provide it after sign in, but you cannot require it. In fact, even if they do provide their email during sign in you should obtain clear consent to send them messages at this address before doing so. You can also use communication techniques such as in app notifications, but again the user can turn these off. You cannot force the user to hear from you if they don't want. – Paulw11 May 26 '23 at 22:11

0 Answers0