Skip to content

Commit dafd753

Browse files
[in_app_purchase] Update iOS Pigeon for non-nullable generics (#7820)
Updates the Pigeon definition to uses non-nullable generics now that it's possible. Leaves a few nullable value types in maps where that corresponds to the public API of the collections passed in, so reflects an API decision rather than a Pigeon limitation. While updating this, also fixes the fact that the Obj-C Pigeon generation wasn't configured to use a prefix, which created the possibility of collision with Apple code due to using an Apple-reserved prefix on all the Pigeon-generated code. Part of flutter/flutter#155891
1 parent 3b7ee86 commit dafd753

25 files changed

+1095
-967
lines changed

packages/in_app_purchase/in_app_purchase_storekit/CHANGELOG.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
## 0.3.18+3
2+
3+
* Updates Pigeon for non-nullable collection type support.
4+
15
## 0.3.18+2
26

37
* Adds support for StoreKit2's `purchase` and `transactions`
48

59
## 0.3.18+1
610

7-
* Adds support for StoreKit2's `canMakePayments` and `products`
11+
* Adds support for StoreKit2's `canMakePayments` and `products`
812

913
## 0.3.18
1014

@@ -53,7 +57,7 @@
5357

5458
## 0.3.12
5559

56-
* Converts `refreshReceipt()`, `startObservingPaymentQueue()`, `stopObservingPaymentQueue()`,
60+
* Converts `refreshReceipt()`, `startObservingPaymentQueue()`, `stopObservingPaymentQueue()`,
5761
`registerPaymentQueueDelegate()`, `removePaymentQueueDelegate()`, `showPriceConsentIfNeeded()` to pigeon.
5862

5963
## 0.3.11
@@ -80,7 +84,7 @@
8084

8185
## 0.3.7
8286

83-
* Adds `Future<SKStorefrontWrapper?> storefront()` in SKPaymentQueueWrapper class.
87+
* Adds `Future<SKStorefrontWrapper?> storefront()` in SKPaymentQueueWrapper class.
8488

8589
## 0.3.6+7
8690

packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/FIAObjectTranslator.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,33 +57,33 @@ NS_ASSUME_NONNULL_BEGIN
5757
withError:(NSString *_Nullable *_Nullable)error
5858
API_AVAILABLE(ios(12.2));
5959

60-
+ (nullable SKPaymentTransactionMessage *)convertTransactionToPigeon:
60+
+ (nullable FIASKPaymentTransactionMessage *)convertTransactionToPigeon:
6161
(nullable SKPaymentTransaction *)transaction;
6262

63-
+ (nullable SKStorefrontMessage *)convertStorefrontToPigeon:(nullable SKStorefront *)storefront
63+
+ (nullable FIASKStorefrontMessage *)convertStorefrontToPigeon:(nullable SKStorefront *)storefront
6464
API_AVAILABLE(ios(13.0));
6565

66-
+ (nullable SKPaymentDiscountMessage *)convertPaymentDiscountToPigeon:
66+
+ (nullable FIASKPaymentDiscountMessage *)convertPaymentDiscountToPigeon:
6767
(nullable SKPaymentDiscount *)discount API_AVAILABLE(ios(12.2));
6868

69-
+ (nullable SKPaymentMessage *)convertPaymentToPigeon:(nullable SKPayment *)payment
69+
+ (nullable FIASKPaymentMessage *)convertPaymentToPigeon:(nullable SKPayment *)payment
7070
API_AVAILABLE(ios(12.2));
7171

72-
+ (nullable SKErrorMessage *)convertSKErrorToPigeon:(nullable NSError *)error;
72+
+ (nullable FIASKErrorMessage *)convertSKErrorToPigeon:(nullable NSError *)error;
7373

74-
+ (nullable SKProductsResponseMessage *)convertProductsResponseToPigeon:
74+
+ (nullable FIASKProductsResponseMessage *)convertProductsResponseToPigeon:
7575
(nullable SKProductsResponse *)payment;
7676

77-
+ (nullable SKProductMessage *)convertProductToPigeon:(nullable SKProduct *)product
77+
+ (nullable FIASKProductMessage *)convertProductToPigeon:(nullable SKProduct *)product
7878
API_AVAILABLE(ios(12.2));
7979

80-
+ (nullable SKProductDiscountMessage *)convertProductDiscountToPigeon:
80+
+ (nullable FIASKProductDiscountMessage *)convertProductDiscountToPigeon:
8181
(nullable SKProductDiscount *)productDiscount API_AVAILABLE(ios(12.2));
8282

83-
+ (nullable SKPriceLocaleMessage *)convertNSLocaleToPigeon:(nullable NSLocale *)locale
83+
+ (nullable FIASKPriceLocaleMessage *)convertNSLocaleToPigeon:(nullable NSLocale *)locale
8484
API_AVAILABLE(ios(12.2));
8585

86-
+ (nullable SKProductSubscriptionPeriodMessage *)convertSKProductSubscriptionPeriodToPigeon:
86+
+ (nullable FIASKProductSubscriptionPeriodMessage *)convertSKProductSubscriptionPeriodToPigeon:
8787
(nullable SKProductSubscriptionPeriod *)period API_AVAILABLE(ios(12.2));
8888
@end
8989

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

Lines changed: 48 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,12 @@ + (SKPaymentDiscount *)getSKPaymentDiscountFromMap:(NSDictionary *)map
291291
return discount;
292292
}
293293

294-
+ (nullable SKPaymentTransactionMessage *)convertTransactionToPigeon:
294+
+ (nullable FIASKPaymentTransactionMessage *)convertTransactionToPigeon:
295295
(nullable SKPaymentTransaction *)transaction API_AVAILABLE(ios(12.2)) {
296296
if (!transaction) {
297297
return nil;
298298
}
299-
SKPaymentTransactionMessage *msg = [SKPaymentTransactionMessage
299+
return [FIASKPaymentTransactionMessage
300300
makeWithPayment:[self convertPaymentToPigeon:transaction.payment]
301301
transactionState:[self convertTransactionStateToPigeon:transaction.transactionState]
302302
originalTransaction:transaction.originalTransaction
@@ -306,10 +306,9 @@ + (nullable SKPaymentTransactionMessage *)convertTransactionToPigeon:
306306
timeIntervalSince1970]]
307307
transactionIdentifier:transaction.transactionIdentifier
308308
error:[self convertSKErrorToPigeon:transaction.error]];
309-
return msg;
310309
}
311310

312-
+ (nullable SKErrorMessage *)convertSKErrorToPigeon:(nullable NSError *)error {
311+
+ (nullable FIASKErrorMessage *)convertSKErrorToPigeon:(nullable NSError *)error {
313312
if (!error) {
314313
return nil;
315314
}
@@ -320,127 +319,117 @@ + (nullable SKErrorMessage *)convertSKErrorToPigeon:(nullable NSError *)error {
320319
userInfo[key] = [FIAObjectTranslator encodeNSErrorUserInfo:value];
321320
}
322321

323-
SKErrorMessage *msg = [SKErrorMessage makeWithCode:error.code
324-
domain:error.domain
325-
userInfo:userInfo];
326-
return msg;
322+
return [FIASKErrorMessage makeWithCode:error.code domain:error.domain userInfo:userInfo];
327323
}
328324

329-
+ (SKPaymentTransactionStateMessage)convertTransactionStateToPigeon:
325+
+ (FIASKPaymentTransactionStateMessage)convertTransactionStateToPigeon:
330326
(SKPaymentTransactionState)state {
331327
switch (state) {
332328
case SKPaymentTransactionStatePurchasing:
333-
return SKPaymentTransactionStateMessagePurchasing;
329+
return FIASKPaymentTransactionStateMessagePurchasing;
334330
case SKPaymentTransactionStatePurchased:
335-
return SKPaymentTransactionStateMessagePurchased;
331+
return FIASKPaymentTransactionStateMessagePurchased;
336332
case SKPaymentTransactionStateFailed:
337-
return SKPaymentTransactionStateMessageFailed;
333+
return FIASKPaymentTransactionStateMessageFailed;
338334
case SKPaymentTransactionStateRestored:
339-
return SKPaymentTransactionStateMessageRestored;
335+
return FIASKPaymentTransactionStateMessageRestored;
340336
case SKPaymentTransactionStateDeferred:
341-
return SKPaymentTransactionStateMessageDeferred;
337+
return FIASKPaymentTransactionStateMessageDeferred;
342338
}
343339
}
344340

345-
+ (nullable SKPaymentMessage *)convertPaymentToPigeon:(nullable SKPayment *)payment
341+
+ (nullable FIASKPaymentMessage *)convertPaymentToPigeon:(nullable SKPayment *)payment
346342
API_AVAILABLE(ios(12.2)) {
347343
if (!payment) {
348344
return nil;
349345
}
350-
SKPaymentMessage *msg = [SKPaymentMessage
346+
return [FIASKPaymentMessage
351347
makeWithProductIdentifier:payment.productIdentifier
352348
applicationUsername:payment.applicationUsername
353349
requestData:[[NSString alloc] initWithData:payment.requestData
354350
encoding:NSUTF8StringEncoding]
355351
quantity:payment.quantity
356352
simulatesAskToBuyInSandbox:payment.simulatesAskToBuyInSandbox
357353
paymentDiscount:[self convertPaymentDiscountToPigeon:payment.paymentDiscount]];
358-
return msg;
359354
}
360355

361-
+ (nullable SKPaymentDiscountMessage *)convertPaymentDiscountToPigeon:
356+
+ (nullable FIASKPaymentDiscountMessage *)convertPaymentDiscountToPigeon:
362357
(nullable SKPaymentDiscount *)discount API_AVAILABLE(ios(12.2)) {
363358
if (!discount) {
364359
return nil;
365360
}
366-
SKPaymentDiscountMessage *msg =
367-
[SKPaymentDiscountMessage makeWithIdentifier:discount.identifier
368-
keyIdentifier:discount.keyIdentifier
369-
nonce:[discount.nonce UUIDString]
370-
signature:discount.signature
371-
timestamp:[discount.timestamp intValue]];
372-
373-
return msg;
361+
return [FIASKPaymentDiscountMessage makeWithIdentifier:discount.identifier
362+
keyIdentifier:discount.keyIdentifier
363+
nonce:[discount.nonce UUIDString]
364+
signature:discount.signature
365+
timestamp:[discount.timestamp intValue]];
374366
}
375367

376-
+ (nullable SKStorefrontMessage *)convertStorefrontToPigeon:(nullable SKStorefront *)storefront
368+
+ (nullable FIASKStorefrontMessage *)convertStorefrontToPigeon:(nullable SKStorefront *)storefront
377369
API_AVAILABLE(ios(13.0)) {
378370
if (!storefront) {
379371
return nil;
380372
}
381-
SKStorefrontMessage *msg = [SKStorefrontMessage makeWithCountryCode:storefront.countryCode
382-
identifier:storefront.identifier];
383-
return msg;
373+
return [FIASKStorefrontMessage makeWithCountryCode:storefront.countryCode
374+
identifier:storefront.identifier];
384375
}
385376

386-
+ (nullable SKProductSubscriptionPeriodMessage *)convertSKProductSubscriptionPeriodToPigeon:
377+
+ (nullable FIASKProductSubscriptionPeriodMessage *)convertSKProductSubscriptionPeriodToPigeon:
387378
(nullable SKProductSubscriptionPeriod *)period API_AVAILABLE(ios(12.2)) {
388379
if (!period) {
389380
return nil;
390381
}
391382

392-
SKSubscriptionPeriodUnitMessage unit;
383+
FIASKSubscriptionPeriodUnitMessage unit;
393384
switch (period.unit) {
394385
case SKProductPeriodUnitDay:
395-
unit = SKSubscriptionPeriodUnitMessageDay;
386+
unit = FIASKSubscriptionPeriodUnitMessageDay;
396387
break;
397388
case SKProductPeriodUnitWeek:
398-
unit = SKSubscriptionPeriodUnitMessageWeek;
389+
unit = FIASKSubscriptionPeriodUnitMessageWeek;
399390
break;
400391
case SKProductPeriodUnitMonth:
401-
unit = SKSubscriptionPeriodUnitMessageMonth;
392+
unit = FIASKSubscriptionPeriodUnitMessageMonth;
402393
break;
403394
case SKProductPeriodUnitYear:
404-
unit = SKSubscriptionPeriodUnitMessageYear;
395+
unit = FIASKSubscriptionPeriodUnitMessageYear;
405396
break;
406397
}
407398

408-
SKProductSubscriptionPeriodMessage *msg =
409-
[SKProductSubscriptionPeriodMessage makeWithNumberOfUnits:period.numberOfUnits unit:unit];
410-
411-
return msg;
399+
return [FIASKProductSubscriptionPeriodMessage makeWithNumberOfUnits:period.numberOfUnits
400+
unit:unit];
412401
}
413402

414-
+ (nullable SKProductDiscountMessage *)convertProductDiscountToPigeon:
403+
+ (nullable FIASKProductDiscountMessage *)convertProductDiscountToPigeon:
415404
(nullable SKProductDiscount *)productDiscount API_AVAILABLE(ios(12.2)) {
416405
if (!productDiscount) {
417406
return nil;
418407
}
419408

420-
SKProductDiscountPaymentModeMessage paymentMode;
409+
FIASKProductDiscountPaymentModeMessage paymentMode;
421410
switch (productDiscount.paymentMode) {
422411
case SKProductDiscountPaymentModeFreeTrial:
423-
paymentMode = SKProductDiscountPaymentModeMessageFreeTrial;
412+
paymentMode = FIASKProductDiscountPaymentModeMessageFreeTrial;
424413
break;
425414
case SKProductDiscountPaymentModePayAsYouGo:
426-
paymentMode = SKProductDiscountPaymentModeMessagePayAsYouGo;
415+
paymentMode = FIASKProductDiscountPaymentModeMessagePayAsYouGo;
427416
break;
428417
case SKProductDiscountPaymentModePayUpFront:
429-
paymentMode = SKProductDiscountPaymentModeMessagePayUpFront;
418+
paymentMode = FIASKProductDiscountPaymentModeMessagePayUpFront;
430419
break;
431420
}
432421

433-
SKProductDiscountTypeMessage type;
422+
FIASKProductDiscountTypeMessage type;
434423
switch (productDiscount.type) {
435424
case SKProductDiscountTypeIntroductory:
436-
type = SKProductDiscountTypeMessageIntroductory;
425+
type = FIASKProductDiscountTypeMessageIntroductory;
437426
break;
438427
case SKProductDiscountTypeSubscription:
439-
type = SKProductDiscountTypeMessageSubscription;
428+
type = FIASKProductDiscountTypeMessageSubscription;
440429
break;
441430
}
442431

443-
SKProductDiscountMessage *msg = [SKProductDiscountMessage
432+
return [FIASKProductDiscountMessage
444433
makeWithPrice:productDiscount.price.description
445434
priceLocale:[self convertNSLocaleToPigeon:productDiscount.priceLocale]
446435
numberOfPeriods:productDiscount.numberOfPeriods
@@ -449,37 +438,33 @@ + (nullable SKProductDiscountMessage *)convertProductDiscountToPigeon:
449438
.subscriptionPeriod]
450439
identifier:productDiscount.identifier
451440
type:type];
452-
453-
return msg;
454441
}
455442

456-
+ (nullable SKPriceLocaleMessage *)convertNSLocaleToPigeon:(nullable NSLocale *)locale
443+
+ (nullable FIASKPriceLocaleMessage *)convertNSLocaleToPigeon:(nullable NSLocale *)locale
457444
API_AVAILABLE(ios(12.2)) {
458445
if (!locale) {
459446
return nil;
460447
}
461-
SKPriceLocaleMessage *msg = [SKPriceLocaleMessage makeWithCurrencySymbol:locale.currencySymbol
462-
currencyCode:locale.currencyCode
463-
countryCode:locale.countryCode];
464-
465-
return msg;
448+
return [FIASKPriceLocaleMessage makeWithCurrencySymbol:locale.currencySymbol
449+
currencyCode:locale.currencyCode
450+
countryCode:locale.countryCode];
466451
}
467452

468-
+ (nullable SKProductMessage *)convertProductToPigeon:(nullable SKProduct *)product
453+
+ (nullable FIASKProductMessage *)convertProductToPigeon:(nullable SKProduct *)product
469454
API_AVAILABLE(ios(12.2)) {
470455
if (!product) {
471456
return nil;
472457
}
473458

474459
NSArray<SKProductDiscount *> *skProductDiscounts = product.discounts;
475-
NSMutableArray<SKProductDiscountMessage *> *pigeonProductDiscounts =
460+
NSMutableArray<FIASKProductDiscountMessage *> *pigeonProductDiscounts =
476461
[NSMutableArray arrayWithCapacity:skProductDiscounts.count];
477462

478463
for (SKProductDiscount *productDiscount in skProductDiscounts) {
479464
[pigeonProductDiscounts addObject:[self convertProductDiscountToPigeon:productDiscount]];
480465
};
481466

482-
SKProductMessage *msg = [SKProductMessage
467+
return [FIASKProductMessage
483468
makeWithProductIdentifier:product.productIdentifier
484469
localizedTitle:product.localizedTitle
485470
localizedDescription:product.localizedDescription
@@ -490,27 +475,24 @@ + (nullable SKProductMessage *)convertProductToPigeon:(nullable SKProduct *)prod
490475
[self convertSKProductSubscriptionPeriodToPigeon:product.subscriptionPeriod]
491476
introductoryPrice:[self convertProductDiscountToPigeon:product.introductoryPrice]
492477
discounts:pigeonProductDiscounts];
493-
494-
return msg;
495478
}
496479

497-
+ (nullable SKProductsResponseMessage *)convertProductsResponseToPigeon:
480+
+ (nullable FIASKProductsResponseMessage *)convertProductsResponseToPigeon:
498481
(nullable SKProductsResponse *)productsResponse API_AVAILABLE(ios(12.2)) {
499482
if (!productsResponse) {
500483
return nil;
501484
}
502485
NSArray<SKProduct *> *skProducts = productsResponse.products;
503-
NSMutableArray<SKProductMessage *> *pigeonProducts =
486+
NSMutableArray<FIASKProductMessage *> *pigeonProducts =
504487
[NSMutableArray arrayWithCapacity:skProducts.count];
505488

506489
for (SKProduct *product in skProducts) {
507490
[pigeonProducts addObject:[self convertProductToPigeon:product]];
508491
};
509492

510-
SKProductsResponseMessage *msg = [SKProductsResponseMessage
493+
return [FIASKProductsResponseMessage
511494
makeWithProducts:pigeonProducts
512495
invalidProductIdentifiers:productsResponse.invalidProductIdentifiers ?: @[]];
513-
return msg;
514496
}
515497

516498
@end

packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import StoreKit
1111
import FlutterMacOS
1212
#endif
1313

14-
public class InAppPurchasePlugin: NSObject, FlutterPlugin, InAppPurchaseAPI {
14+
public class InAppPurchasePlugin: NSObject, FlutterPlugin, FIAInAppPurchaseAPI {
1515
private let receiptManager: FIAPReceiptManager
1616
private var productsCache: NSMutableDictionary = [:]
1717
private var paymentQueueDelegateCallbackChannel: FlutterMethodChannel?
@@ -55,7 +55,7 @@ public class InAppPurchasePlugin: NSObject, FlutterPlugin, InAppPurchaseAPI {
5555
let instance = InAppPurchasePlugin(registrar: registrar)
5656
registrar.addMethodCallDelegate(instance, channel: channel)
5757
registrar.addApplicationDelegate(instance)
58-
SetUpInAppPurchaseAPI(messenger, instance)
58+
SetUpFIAInAppPurchaseAPI(messenger, instance)
5959
if #available(iOS 15.0, macOS 12.0, *) {
6060
InAppPurchase2APISetup.setUp(binaryMessenger: messenger, api: instance)
6161
}
@@ -120,7 +120,7 @@ public class InAppPurchasePlugin: NSObject, FlutterPlugin, InAppPurchaseAPI {
120120
}
121121

122122
public func transactionsWithError(_ error: AutoreleasingUnsafeMutablePointer<FlutterError?>)
123-
-> [SKPaymentTransactionMessage]?
123+
-> [FIASKPaymentTransactionMessage]?
124124
{
125125
return getPaymentQueueHandler()
126126
.getUnfinishedTransactions()
@@ -130,7 +130,7 @@ public class InAppPurchasePlugin: NSObject, FlutterPlugin, InAppPurchaseAPI {
130130
}
131131

132132
public func storefrontWithError(_ error: AutoreleasingUnsafeMutablePointer<FlutterError?>)
133-
-> SKStorefrontMessage?
133+
-> FIASKStorefrontMessage?
134134
{
135135
if #available(iOS 13.0, *), let storefront = getPaymentQueueHandler().storefront {
136136
return FIAObjectTranslator.convertStorefront(toPigeon: storefront)
@@ -140,7 +140,7 @@ public class InAppPurchasePlugin: NSObject, FlutterPlugin, InAppPurchaseAPI {
140140

141141
public func startProductRequestProductIdentifiers(
142142
_ productIdentifiers: [String],
143-
completion: @escaping (SKProductsResponseMessage?, FlutterError?) -> Void
143+
completion: @escaping (FIASKProductsResponseMessage?, FlutterError?) -> Void
144144
) {
145145
let request = getProductRequest(withIdentifiers: Set(productIdentifiers))
146146
let handler = handlerFactory(request)

0 commit comments

Comments
 (0)