Skip to content

Commit

Permalink
Merge pull request #33 from hansemannn/MOD-2375
Browse files Browse the repository at this point in the history
Add iOS 11.2 API's, support product discount
  • Loading branch information
hansemannn authored Jan 24, 2018
2 parents fff4f19 + f01a054 commit 51b93d8
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ios/LICENSE → LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2013 Appcelerator, Inc.
Copyright 2013-present by Axway Appcelerator

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
30 changes: 30 additions & 0 deletions ios/Classes/Discount/TiStorekitProductDiscountProxy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2017 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
#import "TiProxy.h"
#import <StoreKit/StoreKit.h>

#if IS_IOS_11_2

@interface TiStorekitProductDiscountProxy : TiProxy {
SKProductDiscount *_productDiscount;
}

- (id)initWithProductDiscount:(SKProductDiscount *)productDiscount pageContext:(id<TiEvaluator>)context;

- (NSNumber *)price;

- (NSString *)priceLocale;

- (NSDictionary *)subscriptionPeriod;

- (NSNumber *)numberOfPeriods;

- (NSNumber *)paymentMode;

@end

#endif
49 changes: 49 additions & 0 deletions ios/Classes/Discount/TiStorekitProductDiscountProxy.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2017 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/

#import "TiStorekitProductDiscountProxy.h"

@implementation TiStorekitProductDiscountProxy

- (id)initWithProductDiscount:(SKProductDiscount *)productDiscount pageContext:(id<TiEvaluator>)context
{
if (self = [super _initWithPageContext:context]) {
_productDiscount = productDiscount;
}

return self;
}

- (NSNumber *)price
{
return _productDiscount.price;
}

- (NSString *)priceLocale
{
return _productDiscount.priceLocale.localeIdentifier;
}

- (NSDictionary *)subscriptionPeriod
{
return @{
@"numberOfUnits": @(_productDiscount.subscriptionPeriod.numberOfUnits),
@"unit": @(_productDiscount.subscriptionPeriod.unit),
};
}

- (NSNumber *)numberOfPeriods
{
return @(_productDiscount.numberOfPeriods);
}

- (NSNumber *)paymentMode
{
return @(_productDiscount.paymentMode);
}

@end
7 changes: 7 additions & 0 deletions ios/Classes/Product/TiStorekitProduct.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#import "TiProxy.h"
#import "TiStorekitProductDiscountProxy.h"
#import <StoreKit/StoreKit.h>

@interface TiStorekitProduct : TiProxy {
Expand Down Expand Up @@ -37,4 +38,10 @@

- (NSString *)downloadContentVersion;

#if IS_IOS_11_2
- (TiStorekitProductDiscountProxy *)introductoryPrice;

- (NSDictionary *)subscriptionPeriod;
#endif

@end
25 changes: 25 additions & 0 deletions ios/Classes/Product/TiStorekitProduct.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,29 @@ - (NSString *)downloadContentVersion
return [_product downloadContentVersion];
}

#if IS_IOS_11_2
- (TiStorekitProductDiscountProxy *)introductoryPrice
{
if (![TiUtils isIOSVersionOrGreater:@"11.2"]) {
DebugLog(@"[ERROR] The \"introductoryPrice\" property is only available on iOS 11.2 and later.");
return nil;
}

return [[TiStorekitProductDiscountProxy alloc] initWithProductDiscount:_product.introductoryPrice pageContext:self.pageContext];
}

- (NSDictionary *)subscriptionPeriod
{
if (![TiUtils isIOSVersionOrGreater:@"11.2"]) {
DebugLog(@"[ERROR] The \"subscriptionPeriod\" property is only available on iOS 11.2 and later.");
return nil;
}

return @{
@"numberOfUnits": @(_product.subscriptionPeriod.numberOfUnits),
@"unit": @(_product.subscriptionPeriod.unit),
};
}
#endif

@end
13 changes: 11 additions & 2 deletions ios/Classes/TiStoreKitModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,17 @@ - (void)requestReviewDialog:(id)unused

MAKE_SYSTEM_PROP(DOWNLOAD_TIME_REMAINING_UNKNOWN, -1);

#if IS_IOS_11_2
MAKE_SYSTEM_PROP(DISCOUNT_PAYMENT_MODE_PAY_AS_YOU_GO, SKProductDiscountPaymentModePayAsYouGo);
MAKE_SYSTEM_PROP(DISCOUNT_PAYMENT_MODE_PAY_UP_FRONT, SKProductDiscountPaymentModePayUpFront);
MAKE_SYSTEM_PROP(DISCOUNT_PAYMENT_MODE_FREE_TRIAL, SKProductDiscountPaymentModeFreeTrial);

MAKE_SYSTEM_PROP(PERIOD_UNIT_DAY, SKProductPeriodUnitDay);
MAKE_SYSTEM_PROP(PERIOD_UNIT_WEEK, SKProductPeriodUnitWeek);
MAKE_SYSTEM_PROP(PERIOD_UNIT_MONTH, SKProductPeriodUnitMonth);
MAKE_SYSTEM_PROP(PERIOD_UNIT_YEAR, SKProductPeriodUnitYear);
#endif

#pragma mark Utils

+ (NSString *)descriptionFromError:(NSError *)error
Expand Down Expand Up @@ -610,13 +621,11 @@ - (void)request:(SKRequest *)request didFailWithError:(NSError *)error
}
}

#if IS_IOS_11
- (BOOL)paymentQueue:(SKPaymentQueue *)queue shouldAddStorePayment:(SKPayment *)payment forProduct:(SKProduct *)product
{
NSArray<NSString *> *allowedStorePaymentProductIdentifiers = [self valueForKey:@"allowedStorePaymentProductIdentifiers"];

return !allowedStorePaymentProductIdentifiers || allowedStorePaymentProductIdentifiers && [allowedStorePaymentProductIdentifiers containsObject:product.productIdentifier];
}
#endif

@end
6 changes: 3 additions & 3 deletions ios/TiStoreKit_Prefix.pch
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#import <Foundation/Foundation.h>
#endif

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000
#define IS_IOS_11 true
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_11_2
#define IS_IOS_11_2 true
#else
#define IS_IOS_11 false
#define IS_IOS_11_2 false
#endif
2 changes: 2 additions & 0 deletions ios/documentation/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Change Log
<pre>
v4.3.0 Support for the iOS 11.2+ `Discount` API.

v4.2.0 Support for the iOS 11+ property `allowedStorePaymentProductIdentifiers`.

v4.1.0 Support for `requestReviewDialog()`
Expand Down
35 changes: 35 additions & 0 deletions ios/documentation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,41 @@ The CANCELLED state during download request processing.

The value of `timeRemaining` when it cannot create a good estimate.


### DISCOUNT_PAYMENT_MODE_PAY_AS_YOU_GO[int]

The value of the product's `paymentMode`, indicating that the payment mode
of a product discount is billed over a single or multiple billing periods.

### DISCOUNT_PAYMENT_MODE_PAY_UP_FRONT[int]

The value of the product's `paymentMode`, indicating that the payment mode of
a product discount is paid up front.

### DISCOUNT_PAYMENT_MODE_FREE_TRIAL[int]

The value of the product's `paymentMode`, indicating that the payment mode is a free trial.

### PERIOD_UNIT_DAY[int]

The value of the product's `introductoryPrice.subscriptionPeriod.unit` or `subscriptionPeriod.unit`,
indicating an interval lasting one day.

### PERIOD_UNIT_WEEK[int]

The value of the product's `introductoryPrice.subscriptionPeriod.unit` or `subscriptionPeriod.unit`,
indicating an interval lasting one week.

### PERIOD_UNIT_MONTH[int]

The value of the product's `introductoryPrice.subscriptionPeriod.unit` or `subscriptionPeriod.unit`,
indicating an interval lasting one month.

### PERIOD_UNIT_YEAR[int]

The value of the product's `introductoryPrice.subscriptionPeriod.unit` or `subscriptionPeriod.unit`,
indicating an interval lasting one year.

## Events

### transactionState
Expand Down
16 changes: 16 additions & 0 deletions ios/documentation/product.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ The price of the product.

The price of the product, formatted for the store's locale.

### Ti.Storekit.Product.introductoryPrice[Discount] (read-only)

The introductory price of the product, served as a `Discount` proxy.
Includes the following properties:
* price (Number)
* priceLocale (String)
* subscriptionPeriod (Dictionary) { numberOfUnits (Number), unit (number) }
* numberOfPeriods (Number)
* paymentMode (Number, `DISCOUNT_PAYMENT_MODE_*`)

### Ti.Storekit.Product.subscriptionPeriod[Dictionary] (read-only)

The subscription period of the product, served as a dictionary with the following properties.
* numberOfUnits (Number)
* unit (Number, `PERIOD_UNIT_*`)

### Ti.Storekit.Product.locale[string] (read-only)

The locale of the product.
Expand Down
4 changes: 2 additions & 2 deletions ios/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 4.2.0
version: 4.3.0
apiversion: 2
architectures: armv7 i386 x86_64 arm64
description: Apple StoreKit module for in application purchases
Expand All @@ -16,4 +16,4 @@ name: storekit
moduleid: ti.storekit
guid: 67fdca33-590b-498d-bd4e-1fc3a8be0f37
platform: iphone
minsdk: 5.5.0.GA
minsdk: 6.2.2
18 changes: 18 additions & 0 deletions ios/storekit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@
DB0CAEE41EA600EB00AE8D56 /* x509v3.h in Headers */ = {isa = PBXBuildFile; fileRef = DB0CAE991EA600EB00AE8D56 /* x509v3.h */; };
DB0CAF321EA62C8100AE8D56 /* libcrypto.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DB0CAF301EA62C8100AE8D56 /* libcrypto.a */; };
DB0CAF331EA62C8100AE8D56 /* libssl.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DB0CAF311EA62C8100AE8D56 /* libssl.a */; };
DB70CEDF1FD580D000E3A1A0 /* TiStorekitProductDiscountProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = DB70CEDD1FD580D000E3A1A0 /* TiStorekitProductDiscountProxy.h */; };
DB70CEE01FD580D000E3A1A0 /* TiStorekitProductDiscountProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = DB70CEDE1FD580D000E3A1A0 /* TiStorekitProductDiscountProxy.m */; };
DB72C8671F91535800D3E296 /* TiStorekitDownload.m in Sources */ = {isa = PBXBuildFile; fileRef = DB72C8601F91534500D3E296 /* TiStorekitDownload.m */; };
DB72C8681F91535800D3E296 /* TiStorekitProduct.m in Sources */ = {isa = PBXBuildFile; fileRef = DB72C8631F91534500D3E296 /* TiStorekitProduct.m */; };
DB72C8691F91535800D3E296 /* TiStorekitProductRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = DB72C85D1F91534500D3E296 /* TiStorekitProductRequest.m */; };
Expand Down Expand Up @@ -217,6 +219,8 @@
DB0CAE991EA600EB00AE8D56 /* x509v3.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = x509v3.h; sourceTree = "<group>"; };
DB0CAF301EA62C8100AE8D56 /* libcrypto.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libcrypto.a; path = openssl/libcrypto.a; sourceTree = "<group>"; };
DB0CAF311EA62C8100AE8D56 /* libssl.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libssl.a; path = openssl/libssl.a; sourceTree = "<group>"; };
DB70CEDD1FD580D000E3A1A0 /* TiStorekitProductDiscountProxy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = TiStorekitProductDiscountProxy.h; path = Classes/Discount/TiStorekitProductDiscountProxy.h; sourceTree = "<group>"; };
DB70CEDE1FD580D000E3A1A0 /* TiStorekitProductDiscountProxy.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = TiStorekitProductDiscountProxy.m; path = Classes/Discount/TiStorekitProductDiscountProxy.m; sourceTree = "<group>"; };
DB72C85C1F91534500D3E296 /* TiStorekitProductRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TiStorekitProductRequest.h; sourceTree = "<group>"; };
DB72C85D1F91534500D3E296 /* TiStorekitProductRequest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TiStorekitProductRequest.m; sourceTree = "<group>"; };
DB72C85F1F91534500D3E296 /* TiStorekitDownload.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TiStorekitDownload.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -283,6 +287,7 @@
DB72C85E1F91534500D3E296 /* Download */,
DB72C8611F91534500D3E296 /* Product */,
DB72C85B1F91534500D3E296 /* Product Request */,
DB70CEDC1FD5809600E3A1A0 /* Product Discount */,
DB72C8641F91534500D3E296 /* Transaction */,
24DD6CF71134B3F500162E58 /* TiStorekitModule.h */,
24DD6CF81134B3F500162E58 /* TiStoreKitModule.m */,
Expand Down Expand Up @@ -395,6 +400,15 @@
path = ../../openssl;
sourceTree = "<group>";
};
DB70CEDC1FD5809600E3A1A0 /* Product Discount */ = {
isa = PBXGroup;
children = (
DB70CEDD1FD580D000E3A1A0 /* TiStorekitProductDiscountProxy.h */,
DB70CEDE1FD580D000E3A1A0 /* TiStorekitProductDiscountProxy.m */,
);
name = "Product Discount";
sourceTree = "<group>";
};
DB72C85B1F91534500D3E296 /* Product Request */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -470,6 +484,7 @@
DB0CAEA21EA600EB00AE8D56 /* camellia.h in Headers */,
DB0CAE9C1EA600EB00AE8D56 /* asn1.h in Headers */,
DB0CAEBA1EA600EB00AE8D56 /* krb5_asn.h in Headers */,
DB70CEDF1FD580D000E3A1A0 /* TiStorekitProductDiscountProxy.h in Headers */,
DB0CAEA51EA600EB00AE8D56 /* cms.h in Headers */,
DB0CAED11EA600EB00AE8D56 /* safestack.h in Headers */,
DB0CAEAA1EA600EB00AE8D56 /* des_old.h in Headers */,
Expand Down Expand Up @@ -595,6 +610,7 @@
buildActionMask = 2147483647;
files = (
DB72C8671F91535800D3E296 /* TiStorekitDownload.m in Sources */,
DB70CEE01FD580D000E3A1A0 /* TiStorekitProductDiscountProxy.m in Sources */,
DB72C8681F91535800D3E296 /* TiStorekitProduct.m in Sources */,
DB72C8691F91535800D3E296 /* TiStorekitProductRequest.m in Sources */,
DB72C86A1F91535800D3E296 /* TiStorekitTransaction.m in Sources */,
Expand Down Expand Up @@ -622,6 +638,7 @@
"ARCHS[sdk=iphoneos*]" = "$(ARCHS_STANDARD)";
"ARCHS[sdk=iphonesimulator*]" = "$(ARCHS_STANDARD)";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = NO;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DSTROOT = /tmp/TiStorekit.dst;
Expand Down Expand Up @@ -671,6 +688,7 @@
"ARCHS[sdk=iphoneos*]" = "$(ARCHS_STANDARD)";
"ARCHS[sdk=iphonesimulator*]" = "$(ARCHS_STANDARD)";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = NO;
DSTROOT = /tmp/TiStorekit.dst;
ENABLE_BITCODE = YES;
GCC_C_LANGUAGE_STANDARD = c99;
Expand Down
2 changes: 1 addition & 1 deletion ios/titanium.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// OF YOUR TITANIUM SDK YOU'RE BUILDING FOR
//
//
TITANIUM_SDK_VERSION = 6.2.2.GA
TITANIUM_SDK_VERSION = 7.0.1.GA

//
// THESE SHOULD BE OK GENERALLY AS-IS
Expand Down

0 comments on commit 51b93d8

Please sign in to comment.