Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 4cf6f44

Browse files
author
Chris Yang
authored
[in_app_puchase_storekit] handle appStoreReceiptURL is nil (#7069)
* handle nil * versio update
1 parent e41f9f9 commit 4cf6f44

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

packages/in_app_purchase/in_app_purchase_storekit/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.3.5+2
2+
3+
* Fix a crash when `appStoreReceiptURL` is nil.
4+
15
## 0.3.5+1
26

37
* Uses the new `sharedDarwinSource` flag when available.

packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/FIAPReceiptManager.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ @implementation FIAPReceiptManager
2121

2222
- (NSString *)retrieveReceiptWithError:(FlutterError **)flutterError {
2323
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
24+
if (!receiptURL) {
25+
return nil;
26+
}
2427
NSError *receiptError;
2528
NSData *receipt = [self getReceiptData:receiptURL error:&receiptError];
2629
if (!receipt || receiptError) {

packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,23 @@ - (void)testRetrieveReceiptDataSuccess {
313313
XCTAssert([result isKindOfClass:[NSString class]]);
314314
}
315315

316+
- (void)testRetrieveReceiptDataNil {
317+
NSBundle *mockBundle = OCMPartialMock([NSBundle mainBundle]);
318+
OCMStub(mockBundle.appStoreReceiptURL).andReturn(nil);
319+
XCTestExpectation *expectation = [self expectationWithDescription:@"nil receipt data retrieved"];
320+
FlutterMethodCall *call = [FlutterMethodCall
321+
methodCallWithMethodName:@"-[InAppPurchasePlugin retrieveReceiptData:result:]"
322+
arguments:nil];
323+
__block NSDictionary *result;
324+
[self.plugin handleMethodCall:call
325+
result:^(id r) {
326+
result = r;
327+
[expectation fulfill];
328+
}];
329+
[self waitForExpectations:@[ expectation ] timeout:5];
330+
XCTAssertNil(result);
331+
}
332+
316333
- (void)testRetrieveReceiptDataError {
317334
XCTestExpectation *expectation = [self expectationWithDescription:@"receipt data retrieved"];
318335
FlutterMethodCall *call = [FlutterMethodCall

packages/in_app_purchase/in_app_purchase_storekit/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: in_app_purchase_storekit
22
description: An implementation for the iOS and macOS platforms of the Flutter `in_app_purchase` plugin. This uses the StoreKit Framework.
33
repository: https://github.com/flutter/plugins/tree/main/packages/in_app_purchase/in_app_purchase_storekit
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+in_app_purchase%22
5-
version: 0.3.5+1
5+
version: 0.3.5+2
66

77
environment:
88
sdk: ">=2.14.0 <3.0.0"

0 commit comments

Comments
 (0)