Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal Crash: Unexpectedly found nil while implicitly unwrapping an Optional value #83

Closed
Jerland2 opened this issue Apr 3, 2021 · 3 comments
Labels

Comments

@Jerland2
Copy link

Jerland2 commented Apr 3, 2021

Version: TPInAppReceipt 3.1.0 using SPM
Setup: Testing in sandbox env using IAP configuration file.
Crash: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value: file TPInAppReceipt/InAppReceipt+ASN1Decodable.swift, line 242

		while !container.isAtEnd
		{
			do
			{
				var attributeContainer = try container.nestedUnkeyedContainer(for: ReceiptAttribute.template) as! ASN1UnkeyedDecodingContainerProtocol
				let type: Int32 = try attributeContainer.decode(Int32.self)
				let _ = try attributeContainer.skip(template: .universal(ASN1Identifier.Tag.integer)) // Consume
				var valueContainer = try attributeContainer.nestedUnkeyedContainer(for: .universal(ASN1Identifier.Tag.octetString)) as! ASN1UnkeyedDecodingContainerProtocol
				//let attribute = try container.decode(ReceiptAttribute.self)
				
				switch type
				{
				case InAppReceiptField.quantity:
					quantity = try valueContainer.decode(Int.self)
				case InAppReceiptField.productIdentifier:
					productIdentifier = try valueContainer.decode(String.self)
				case InAppReceiptField.productType:
					productType = Type(rawValue: try valueContainer.decode(Int32.self)) ?? .unknown
				case InAppReceiptField.transactionIdentifier:
					transactionIdentifier = try valueContainer.decode(String.self)
				case InAppReceiptField.purchaseDate:
					let purchaseDateString = try valueContainer.decode(String.self, template: .universal(ASN1Identifier.Tag.ia5String))
					purchaseDate = purchaseDateString.rfc3339date()!
				case InAppReceiptField.originalTransactionIdentifier:
					originalTransactionIdentifier = try valueContainer.decode(String.self)
				case InAppReceiptField.originalPurchaseDate:
					let originalPurchaseDateString = try valueContainer.decode(String.self, template: .universal(ASN1Identifier.Tag.ia5String))
					originalPurchaseDate = originalPurchaseDateString.rfc3339date()!
				case InAppReceiptField.subscriptionExpirationDate:
					let str = try valueContainer.decode(String.self, template: .universal(ASN1Identifier.Tag.ia5String))
					let subscriptionExpirationDateString = str == "" ? nil : str
					subscriptionExpirationDate = subscriptionExpirationDateString?.rfc3339date()
				case InAppReceiptField.cancellationDate:
					let str = try valueContainer.decode(String.self, template: .universal(ASN1Identifier.Tag.ia5String))
					let cancellationDateString = str == "" ? nil : str
					cancellationDate = cancellationDateString?.rfc3339date()
				case InAppReceiptField.webOrderLineItemID:
					webOrderLineItemID = try valueContainer.decode(Int.self)
				case InAppReceiptField.subscriptionTrialPeriod:
					subscriptionTrialPeriod = (try valueContainer.decode(Int32.self)) != 0
				case InAppReceiptField.subscriptionIntroductoryPricePeriod:
					subscriptionIntroductoryPricePeriod = (try valueContainer.decode(Int32.self)) != 0
				case InAppReceiptField.promotionalOfferIdentifier:
					promotionalOfferIdentifier = try valueContainer.decode(String.self)
				default:
					break
				}
			}
		}
		
		self.originalTransactionIdentifier = originalTransactionIdentifier
		self.productIdentifier = productIdentifier
		self.transactionIdentifier = transactionIdentifier
		self.purchaseDate = purchaseDate
		self.originalPurchaseDate = originalPurchaseDate // FATAL ERROR OCCURS HERE
	}

This causes application to crash on all subsequent runs after purchasing the first IAP. Fatal error commented with "// FATAL ERROR OCCURS HERE" in the above snippet.

Will be rolling back to 3.0.2 until resolved. 3.0.2 does not exhibit this behavior.

@tikhop
Copy link
Owner

tikhop commented Apr 3, 2021

Hi @Jerland2,

Thanks for the report, I'm looking into it.

@tikhop tikhop added the bug label Apr 3, 2021
@tikhop
Copy link
Owner

tikhop commented Apr 3, 2021

@Jerland2 Confirmed. I will push a fix in a few. Thanks again.

tikhop pushed a commit that referenced this issue Apr 3, 2021
…ase.originalPurchaseDate is nil in StoreKitTest. (#83)
@tikhop
Copy link
Owner

tikhop commented Apr 3, 2021

@Jerland2 Just updated cocoapods. Thanks again for the report.

@tikhop tikhop closed this as completed Apr 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants