forked from mirrors/linphone-iphone
inapp: handle some more cases when account expires and so on...
This commit is contained in:
parent
9fee274061
commit
9a3c241e48
7 changed files with 66 additions and 60 deletions
|
|
@ -468,7 +468,7 @@
|
|||
</connections>
|
||||
</button>
|
||||
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="These parameters were retrieved from a remote provisioning profile." textAlignment="center" lineBreakMode="wordWrap" numberOfLines="7" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="RHE-hi-dfB" userLabel="remoteParamsLabel">
|
||||
<rect key="frame" x="34" y="414" width="254" height="82"/>
|
||||
<rect key="frame" x="34" y="414.00000272146076" width="254" height="82"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="11"/>
|
||||
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
#define IAPNotReadyYet @"IAPNotReadyYet" // startup status, manager is not ready yet
|
||||
#define IAPAvailableSucceeded @"IAPAvailableSucceeded" //no data
|
||||
#define IAPAvailableFailed @"IAPAvailableFailed" //data: invalid_product_ids
|
||||
#define IAPAvailableFailed @"IAPAvailableFailed" //data: error_msg
|
||||
#define IAPPurchaseTrying @"IAPPurchaseTrying" //data: product_id
|
||||
#define IAPPurchaseFailed @"IAPPurchaseFailed" //data: product_id, error_msg
|
||||
#define IAPPurchaseSucceeded @"IAPPurchaseSucceeded" //data: product_id, expires_date
|
||||
|
|
|
|||
|
|
@ -104,13 +104,21 @@
|
|||
for (NSString *invalidIdentifier in response.invalidProductIdentifiers) {
|
||||
LOGW(@"Found product Identifier with invalid ID '%@'", invalidIdentifier);
|
||||
}
|
||||
NSDictionary* dict = @{@"invalid_product_ids": response.invalidProductIdentifiers};
|
||||
NSDictionary* dict = @{@"error_msg": NSLocalizedString(@"Invalid products identifier", nil)};
|
||||
[self postNotificationforStatus:IAPAvailableFailed withDict:dict];
|
||||
} else {
|
||||
[self postNotificationforStatus:IAPAvailableSucceeded withDict:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)request:(SKRequest *)request didFailWithError:(NSError *)error {
|
||||
LOGE(@"Impossible to retrieve list of products: %@", [error localizedFailureReason]);
|
||||
NSDictionary* dict = @{@"error_msg": error ? [error localizedDescription] : NSLocalizedString(@"Product not available", commit)};
|
||||
[self postNotificationforStatus:IAPAvailableFailed withDict:dict];
|
||||
//well, let's retry...
|
||||
[self loadProducts];
|
||||
}
|
||||
|
||||
#pragma mark Other
|
||||
- (BOOL)isPurchasedWithID:(NSString *)productID {
|
||||
for (NSString *prod in _productsIDPurchased) {
|
||||
|
|
@ -178,11 +186,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
- (void)request:(SKRequest *)skrequest didFailWithError:(NSError *)error {
|
||||
LOGE(@"Did not get receipt: %@", error.localizedDescription);
|
||||
[self setStatus:IAPReceiptFailed];
|
||||
}
|
||||
|
||||
- (void)validateReceipt: (SKPaymentTransaction*)transaction {
|
||||
NSString *receiptBase64 = nil;
|
||||
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
|
||||
|
|
@ -307,29 +310,41 @@
|
|||
|
||||
- (void)XMLRPCRequest:(XMLRPCRequest *)request didReceiveResponse:(XMLRPCResponse *)response {
|
||||
LOGI(@"XMLRPC response %@: %@", [request method], [response body]);
|
||||
NSString* productID = [[LinphoneManager instance] lpConfigStringForKey:@"paid_account_id" forSection:@"in_app_purchase"];
|
||||
|
||||
// validation succeeded
|
||||
if(! [response isFault] && [response object] != nil) {
|
||||
if([[request method] isEqualToString:@"get_expiration_date"]) {
|
||||
double expirationTime = [[response object] doubleValue];
|
||||
NSString* productID = [[LinphoneManager instance] lpConfigStringForKey:@"paid_account_id" forSection:@"in_app_purchase"];
|
||||
NSDate * date = nil;
|
||||
if(expirationTime < 1) {
|
||||
//first remove it from list
|
||||
[_productsIDPurchased removeObject:productID];
|
||||
|
||||
double expirationTime = [[response object] doubleValue] / 1000;
|
||||
NSDate * expirationDate = [NSDate dateWithTimeIntervalSince1970:expirationTime];
|
||||
NSDate *now = [[NSDate alloc] init];
|
||||
if (([expirationDate earlierDate:now] == expirationDate) || (expirationTime < 1)) {
|
||||
LOGI(@"Account has expired");
|
||||
[[PhoneMainView instance] changeCurrentView:[InAppProductsViewController compositeViewDescription]];
|
||||
date = [NSDate dateWithTimeIntervalSince1970:0];
|
||||
expirationDate = [NSDate dateWithTimeIntervalSince1970:0];
|
||||
} else {
|
||||
date = [NSDate dateWithTimeIntervalSince1970:expirationTime];
|
||||
[_productsIDPurchased addObject:productID];
|
||||
}
|
||||
NSDictionary* dict = @{@"product_id": productID, @"expires_date": date};
|
||||
NSDictionary* dict = @{@"product_id": productID, @"expires_date": expirationDate};
|
||||
[self postNotificationforStatus:IAPReceiptSucceeded withDict:dict];
|
||||
} else if([[request method] isEqualToString:@"create_account_from_in_app_purchase"]) {
|
||||
double timeinterval = [[response object] doubleValue];
|
||||
NSString* productID = [[LinphoneManager instance] lpConfigStringForKey:@"paid_account_id" forSection:@"in_app_purchase"];
|
||||
[_productsIDPurchased removeObject:productID];
|
||||
|
||||
double timeinterval = [[response object] doubleValue] / 1000;
|
||||
if (timeinterval != -2) {
|
||||
NSDate *date = [NSDate dateWithTimeIntervalSince1970:timeinterval];
|
||||
[_productsIDPurchased addObject:productID];
|
||||
NSDictionary* dict = @{@"product_id": productID, @"expires_date": date};
|
||||
NSDate *expirationDate = [NSDate dateWithTimeIntervalSince1970:timeinterval];
|
||||
NSDate *now = [[NSDate alloc] init];
|
||||
if ([expirationDate earlierDate:now] == expirationDate) {
|
||||
LOGI(@"Account has expired");
|
||||
[[PhoneMainView instance] changeCurrentView:[InAppProductsViewController compositeViewDescription]];
|
||||
expirationDate = [NSDate dateWithTimeIntervalSince1970:0];
|
||||
} else {
|
||||
[_productsIDPurchased addObject:productID];
|
||||
}
|
||||
NSDictionary* dict = @{@"product_id": productID, @"expires_date": expirationDate};
|
||||
[self postNotificationforStatus:IAPPurchaseSucceeded withDict:dict];
|
||||
} else {
|
||||
NSDictionary* dict = @{@"product_id": productID, @"error_msg": @"Unknown error"};
|
||||
|
|
|
|||
|
|
@ -20,38 +20,6 @@
|
|||
- (void)viewWillAppear:(BOOL)animated {
|
||||
currentExpanded = -1;
|
||||
iapm = [[LinphoneManager instance] iapManager];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(onIAPPurchaseNotification:)
|
||||
name:IAPAvailableSucceeded
|
||||
object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(onIAPPurchaseNotification:)
|
||||
name:IAPRestoreSucceeded
|
||||
object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(onIAPPurchaseNotification:)
|
||||
name:IAPPurchaseSucceeded
|
||||
object:nil];
|
||||
[[self tableView] reloadData];
|
||||
}
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated {
|
||||
[super viewWillDisappear:animated];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self
|
||||
name:IAPAvailableSucceeded
|
||||
object:nil];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self
|
||||
name:IAPRestoreSucceeded
|
||||
object:nil];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self
|
||||
name:IAPPurchaseSucceeded
|
||||
object:nil];
|
||||
}
|
||||
|
||||
- (void)onIAPPurchaseNotification:(NSNotification*)notif {
|
||||
[[self tableView] reloadData];
|
||||
}
|
||||
|
||||
#pragma mark - Table view data source
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
}
|
||||
|
||||
@property (nonatomic, retain) IBOutlet InAppProductsTableViewController* tableController;
|
||||
@property (retain, nonatomic) IBOutlet UIView *waitView;
|
||||
- (IBAction)onRestoreClicked:(UIButton *)sender;
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
[_tableController release];
|
||||
|
||||
[_waitView release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
|
@ -34,18 +35,27 @@
|
|||
|
||||
- (void)viewWillAppear:(BOOL)animated {
|
||||
[super viewWillAppear:animated];
|
||||
// [[NSNotificationCenter defaultCenter] addObserver:self
|
||||
// selector:@selector(textReceivedEvent:)
|
||||
// name:kLinphoneTextReceived
|
||||
// object:nil];
|
||||
for (NSString* notification in [NSArray arrayWithObjects:IAPAvailableSucceeded, IAPRestoreSucceeded, IAPPurchaseSucceeded, IAPReceiptSucceeded, IAPPurchaseTrying, nil]) {
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(onIAPPurchaseNotification:)
|
||||
name:notification
|
||||
object:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated {
|
||||
[super viewWillDisappear:animated];
|
||||
for (NSString* notification in [NSArray arrayWithObjects:IAPAvailableSucceeded, IAPRestoreSucceeded, IAPPurchaseSucceeded, IAPReceiptSucceeded, IAPPurchaseTrying, nil]) {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self
|
||||
name:notification
|
||||
object:nil];
|
||||
}
|
||||
}
|
||||
|
||||
// [[NSNotificationCenter defaultCenter] removeObserver:self
|
||||
// name:kLinphoneTextReceived
|
||||
// object:nil];
|
||||
- (void)onIAPPurchaseNotification:(NSNotification*)notif {
|
||||
InAppProductsManager *iapm = [[LinphoneManager instance] iapManager];
|
||||
[[_tableController tableView] reloadData];
|
||||
[_waitView setHidden:([[iapm productsAvailable] count] != 0 && ![notif.name isEqualToString:IAPPurchaseTrying])];
|
||||
}
|
||||
|
||||
#pragma mark - UICompositeViewDelegate Functions
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
<connections>
|
||||
<outlet property="tableController" destination="FRQ-Fw-iZ8" id="HVZ-37-Tau"/>
|
||||
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
|
||||
<outlet property="waitView" destination="4pA-a2-gQ7" id="4f0-jJ-Wv4"/>
|
||||
</connections>
|
||||
</placeholder>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
||||
|
|
@ -19,7 +20,7 @@
|
|||
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="grouped" separatorStyle="default" rowHeight="44" sectionHeaderHeight="1" sectionFooterHeight="10" id="fwu-cz-Gse" userLabel="productsTable">
|
||||
<rect key="frame" x="0.0" y="38" width="320" height="422"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
|
||||
<color key="backgroundColor" red="0.93725490196078431" green="0.93725490196078431" blue="0.95686274509803926" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<connections>
|
||||
<outlet property="dataSource" destination="FRQ-Fw-iZ8" id="uQQ-fT-hHp"/>
|
||||
<outlet property="delegate" destination="FRQ-Fw-iZ8" id="2Dx-aQ-XVB"/>
|
||||
|
|
@ -35,6 +36,17 @@
|
|||
<action selector="onRestoreClicked:" destination="-1" eventType="touchUpInside" id="ZYY-WP-1of"/>
|
||||
</connections>
|
||||
</button>
|
||||
<view hidden="YES" alpha="0.49999999999999961" contentMode="scaleToFill" id="4pA-a2-gQ7" userLabel="waitView">
|
||||
<rect key="frame" x="0.0" y="0.0" width="320" height="460"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<activityIndicatorView opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" animating="YES" style="whiteLarge" id="K5m-Dx-cXk" userLabel="spinner">
|
||||
<rect key="frame" x="142" y="211" width="37" height="37"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
|
||||
</activityIndicatorView>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
|
||||
</view>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
|
||||
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue