I am implementing Apple Wallet, where I need to add the card to the wallet. I am trying to convert the certificates, nonce and nonceSignature that I am receiving in the addPaymentPassViewController(_:generateRequestWithCertificateChain:nonce:nonceSignature:completionHandler:) delegate method of PKAddPaymentPassViewControllerDelegate of PassKit, from 'Data' to String encoded in 'UTF8' format.
However, the conversion returns nil while converting from Data to String using utf8 encoding format.
Pls find an image attached. I have highlighted where the conversion fails
Could any please help me to identify what is going wrong?
class ViewController: PKAddPaymentPassViewControllerDelegate {
		func addPaymentPassViewController(_ controller: PKAddPaymentPassViewController, generateRequestWithCertificateChain certificates: [Data], nonce: Data, nonceSignature: Data, completionHandler handler: @escaping (PKAddPaymentPassRequest) -> Void) {
				
				var encodedCertificateString = ""
&#9;&#9;&#9;&#9;for index in 0..<certificates.count {
&#9;&#9;&#9;&#9;&#9;&#9;if let encodedCertString = String(data: certificates[index], encoding: .utf8) {
&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;encodedCertificateString.append(encodedCertString)
&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;if index != (certificates.count-1) {
&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;encodedCertificateString.append(", ")
&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}
&#9;&#9;&#9;&#9;&#9;&#9;}
&#9;&#9;&#9;&#9;}
&#9;&#9;}
&#9;&#9;
&#9;&#9;func addPaymentPassViewController(_ controller: PKAddPaymentPassViewController, didFinishAdding pass: PKPaymentPass?, error: Error?) {
&#9;&#9;&#9;&#9;controller.dismiss()
&#9;&#9;}
}
Post
Replies
Boosts
Views
Activity
I am implementing Apple Wallet, where I need to add the card to the wallet. My payment gateway requires me to send a 6 digit alphanumeric nonce to them. However, if I try to convert the nonce which is of type Data, that I receive in the generateRequestWithCertificateChain PassKit delegate method, to HexEncoding String, I am getting 8 character String.
How to convert this nonce to a 6 digit hexString?
func addPaymentPassViewController(_ controller: PKAddPaymentPassViewController, generateRequestWithCertificateChain certificates: [Data], nonce: Data, nonceSignature: Data, completionHandler handler: @escaping (PKAddPaymentPassRequest) -> Void)
I am converting nonce data to hexString using the following method
func hexEncodedString(options: HexEncodingOptions = []) -> String {
		let hexDigits = Array((options.contains(.upperCase) ? "0123456789ABCDEF" : "0123456789abcdef").utf16)
		var chars: [unichar] = []
		chars.reserveCapacity(2 * count)
		for byte in self {
				chars.append(hexDigits[Int(byte / 16)])
				chars.append(hexDigits[Int(byte % 16)])
		}
		return String(utf16CodeUnits: chars, count: chars.count)
}
According to the App Check Firebase Documentation, it is said to add the App Attest capability to your app. However, I am not able to find any such capability in XCode. Any insights on this?
Note: We have enabled capability in the provision profiles
Documentation Link: https://firebase.google.com/docs/app-check/ios/app-attest-provider#install-sdk
Does swift have default support for SHA3-256 hashing algorithm for all devices iOS 12 and above?