Is there a way to communicate with user if they have used their Apple ID as phone number

100 Views Asked by At

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

0

There are 0 best solutions below