Skip to content

Commit

Permalink
v0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir committed Jan 28, 2018
1 parent b3e4be9 commit 37d04e0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [0.1.1] - iOS Support
Library is tested on iOS. Feature parity for both iOS and Android.

## [0.1.0] - Billing
New breaking API to address caching of products and purchases.

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ testing has been limited.
[Pull Requests](https://github.com/VolodymyrLykhonis/flutter_billing/pulls) are welcome.

## Using
Add `flutter_billing: 0.1.0` as a dependency in `pubspec.yaml`.
Add `flutter_billing: 0.1.1` as a dependency in `pubspec.yaml`.

Create an instance of the plugin:
```dart
Expand Down Expand Up @@ -57,5 +57,4 @@ final bool purchased = await billing.purchase(productId);
## Limitations
This is just an initial version of the plugin. There are still some limitations:

- iOS implementation is currently under testing
- Only non-consumable in app products are supported
2 changes: 2 additions & 0 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@
ARCHS = arm64;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
DEVELOPMENT_TEAM = "";
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand Down Expand Up @@ -470,6 +471,7 @@
ARCHS = arm64;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
DEVELOPMENT_TEAM = "";
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand Down
23 changes: 13 additions & 10 deletions ios/Classes/BillingPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ @interface BillingPlugin()
@property (atomic, retain) NSMutableDictionary<NSValue*, FlutterResult>* fetchProducts;
@property (atomic, retain) NSMutableDictionary<SKPayment*, FlutterResult>* requestedPayments;
@property (atomic, retain) NSArray<SKProduct*>* products;
@property (atomic, retain) NSSet<NSString*>* purchases;
@property (atomic, retain) NSMutableSet<NSString*>* purchases;
@property (nonatomic, retain) FlutterMethodChannel* channel;

@end
Expand Down Expand Up @@ -36,7 +36,7 @@ - (instancetype)init {
self.fetchProducts = [[NSMutableDictionary alloc] init];
self.requestedPayments = [[NSMutableDictionary alloc] init];
self.products = [[NSArray alloc] init];
self.purchases = [[NSSet alloc] init];
self.purchases = [[NSMutableSet alloc] init];

return self;
}
Expand Down Expand Up @@ -98,22 +98,22 @@ - (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedW
- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {
NSArray<FlutterResult>* results = [NSArray arrayWithArray:fetchPurchases];
[fetchPurchases removeAllObjects];

NSArray<NSString*>* productIdentifiers = [purchases allObjects];
[results enumerateObjectsUsingBlock:^(FlutterResult result, NSUInteger idx, BOOL* stop) {
result(productIdentifiers);
}];
}

- (void)purchased:(NSArray<SKPaymentTransaction*>*)transactions {
NSArray<FlutterResult>* results = [[NSArray alloc] init];
NSMutableArray<FlutterResult>* results = [[NSMutableArray alloc] init];

[transactions enumerateObjectsUsingBlock:^(SKPaymentTransaction* transaction, NSUInteger idx, BOOL* stop) {
[purchases setByAddingObject:transaction.payment.productIdentifier];
[purchases addObject:transaction.payment.productIdentifier];
FlutterResult result = [requestedPayments objectForKey:transaction.payment];
if (result != nil) {
[requestedPayments removeObjectForKey:transaction.payment];
[results arrayByAddingObject:result];
[results addObject:result];
}
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}];
Expand All @@ -128,7 +128,7 @@ - (void)restored:(NSArray<SKPaymentTransaction*>*)transactions {
[transactions enumerateObjectsUsingBlock:^(SKPaymentTransaction* transaction, NSUInteger idx, BOOL* stop) {
SKPaymentTransaction* original = transaction.originalTransaction;
if (original != nil) {
[purchases setByAddingObject:original.payment.productIdentifier];
[purchases addObject:original.payment.productIdentifier];
}
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}];
Expand Down Expand Up @@ -173,16 +173,19 @@ - (void)fetchProducts:(NSArray<NSString*>*)identifiers result:(FlutterResult)res
}

- (void)request:(SKRequest *)request didFailWithError:(NSError *)error {
FlutterResult result = [fetchProducts objectForKey:[NSValue valueWithNonretainedObject:request]];
NSValue* key = [NSValue valueWithNonretainedObject:request];
FlutterResult result = [fetchProducts objectForKey:key];
if (result != nil) {
[fetchProducts removeObjectForKey:[NSValue valueWithNonretainedObject:request]];
[fetchProducts removeObjectForKey:key];
result([FlutterError errorWithCode:@"ERROR" message:@"Failed to make IAP request!" details:nil]);
}
}

- (void)productsRequest:(nonnull SKProductsRequest *)request didReceiveResponse:(nonnull SKProductsResponse *)response {
FlutterResult result = [fetchProducts objectForKey:[NSValue valueWithNonretainedObject:request]];
NSValue* key = [NSValue valueWithNonretainedObject:request];
FlutterResult result = [fetchProducts objectForKey:key];
if (result == nil) return;
[fetchProducts removeObjectForKey:key];

NSNumberFormatter* currencyFormatter = [[NSNumberFormatter alloc] init];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_billing
description: A flutter plugin to communicate with billing on iOS and Android.
version: 0.1.0
version: 0.1.1
author: Volodymyr Lykhonis <[email protected]>
homepage: http://vladimirlichonos.com

Expand Down

0 comments on commit 37d04e0

Please sign in to comment.