mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-23 06:08:07 +00:00
inapp: plug it in wizard and do not query server more than necessary
This commit is contained in:
parent
e22d65b898
commit
3e275a95b1
8 changed files with 174 additions and 86 deletions
|
|
@ -19,6 +19,8 @@
|
|||
<outlet property="provisionedDomain" destination="wRB-Sh-K8J" id="Ieb-x8-yL4"/>
|
||||
<outlet property="provisionedPassword" destination="ClH-fT-a8N" id="h61-p1-4qG"/>
|
||||
<outlet property="provisionedUsername" destination="MyR-eX-QTa" id="gmr-FI-hpH"/>
|
||||
<outlet property="purchaseButton" destination="uIp-br-8Kv" id="Ov2-V4-LLx"/>
|
||||
<outlet property="registerButton" destination="77" id="A9h-Es-kxv"/>
|
||||
<outlet property="remoteProvisioningButton" destination="Kbn-dL-C5h" id="PPk-DJ-nEb"/>
|
||||
<outlet property="transportChooser" destination="Nrv-SM-lMf" id="7iR-aG-eQf"/>
|
||||
<outlet property="validateAccountView" destination="101" id="112"/>
|
||||
|
|
@ -42,7 +44,7 @@
|
|||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
|
||||
<accessibility key="accessibilityConfiguration" label="Account setup assistant"/>
|
||||
<fontDescription key="fontDescription" type="italicSystem" pointSize="20"/>
|
||||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<nil key="highlightedColor"/>
|
||||
<color key="shadowColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<size key="shadowOffset" width="-1" height="-1"/>
|
||||
|
|
@ -73,7 +75,7 @@
|
|||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" heightSizable="YES" flexibleMaxY="YES"/>
|
||||
<accessibility key="accessibilityConfiguration" label="Account setup assistant"/>
|
||||
<fontDescription key="fontDescription" type="italicSystem" pointSize="20"/>
|
||||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<nil key="highlightedColor"/>
|
||||
<color key="shadowColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<size key="shadowOffset" width="-1" height="-1"/>
|
||||
|
|
@ -147,7 +149,7 @@
|
|||
<color key="titleColor" red="0.72549019609999998" green="0.76862745099999996" blue="0.79607843140000001" alpha="1" colorSpace="deviceRGB"/>
|
||||
</state>
|
||||
<connections>
|
||||
<action selector="onPurchaseAccountClick:" destination="-1" eventType="touchUpInside" id="dQ7-Ig-hvt"/>
|
||||
<action selector="onRemoteProvisioningClick:" destination="-1" eventType="touchUpInside" id="Ruh-fu-0Vu"/>
|
||||
</connections>
|
||||
</button>
|
||||
</subviews>
|
||||
|
|
@ -162,7 +164,7 @@
|
|||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" heightSizable="YES" flexibleMaxY="YES"/>
|
||||
<accessibility key="accessibilityConfiguration" label="Account setup assistant"/>
|
||||
<fontDescription key="fontDescription" type="italicSystem" pointSize="20"/>
|
||||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<nil key="highlightedColor"/>
|
||||
<color key="shadowColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<size key="shadowOffset" width="-1" height="-1"/>
|
||||
|
|
@ -237,6 +239,22 @@
|
|||
<action selector="onRegisterClick:" destination="-1" eventType="touchUpInside" id="113"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button hidden="YES" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" adjustsImageWhenHighlighted="NO" lineBreakMode="middleTruncation" id="uIp-br-8Kv" userLabel="purchaseButton" customClass="UILinphoneButton">
|
||||
<rect key="frame" x="33" y="481" width="255" height="73"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES"/>
|
||||
<accessibility key="accessibilityConfiguration" label="Purchase"/>
|
||||
<fontDescription key="fontDescription" type="boldSystem" pointSize="20"/>
|
||||
<state key="normal" title="Purchase" backgroundImage="button_background_default.png">
|
||||
<color key="titleColor" red="0.35686274509999999" green="0.39607843139999999" blue="0.43529411759999997" alpha="1" colorSpace="deviceRGB"/>
|
||||
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
|
||||
</state>
|
||||
<state key="highlighted" backgroundImage="button_background_over.png">
|
||||
<color key="titleColor" red="0.72549019609999998" green="0.76862745099999996" blue="0.79607843140000001" alpha="1" colorSpace="deviceRGB"/>
|
||||
</state>
|
||||
<connections>
|
||||
<action selector="onPurchaseAccountClick:" destination="-1" eventType="touchUpInside" id="BR1-hP-14E"/>
|
||||
</connections>
|
||||
</button>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
|
||||
</view>
|
||||
|
|
@ -249,7 +267,7 @@
|
|||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" heightSizable="YES" flexibleMaxY="YES"/>
|
||||
<accessibility key="accessibilityConfiguration" label="Account setup assistant"/>
|
||||
<fontDescription key="fontDescription" type="italicSystem" pointSize="20"/>
|
||||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<nil key="highlightedColor"/>
|
||||
<color key="shadowColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<size key="shadowOffset" width="-1" height="-1"/>
|
||||
|
|
@ -309,7 +327,7 @@
|
|||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" heightSizable="YES" flexibleMaxY="YES"/>
|
||||
<accessibility key="accessibilityConfiguration" label="Account setup assistant"/>
|
||||
<fontDescription key="fontDescription" type="italicSystem" pointSize="20"/>
|
||||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<nil key="highlightedColor"/>
|
||||
<color key="shadowColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<size key="shadowOffset" width="-1" height="-1"/>
|
||||
|
|
@ -389,7 +407,7 @@
|
|||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" heightSizable="YES" flexibleMaxY="YES"/>
|
||||
<accessibility key="accessibilityConfiguration" label="Account setup assistant"/>
|
||||
<fontDescription key="fontDescription" type="italicSystem" pointSize="20"/>
|
||||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<nil key="highlightedColor"/>
|
||||
<color key="shadowColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<size key="shadowOffset" width="-1" height="-1"/>
|
||||
|
|
@ -450,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"/>
|
||||
|
|
@ -468,7 +486,7 @@
|
|||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" heightSizable="YES" flexibleMaxY="YES"/>
|
||||
<accessibility key="accessibilityConfiguration" label="Account setup assistant"/>
|
||||
<fontDescription key="fontDescription" type="italicSystem" pointSize="20"/>
|
||||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<nil key="highlightedColor"/>
|
||||
<color key="shadowColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<size key="shadowOffset" width="-1" height="-1"/>
|
||||
|
|
|
|||
|
|
@ -25,9 +25,12 @@
|
|||
extern NSString *const kLinphoneIAPurchaseNotification;
|
||||
|
||||
@interface InAppProductsXMLRPCDelegate : NSObject <XMLRPCConnectionDelegate>
|
||||
|
||||
@end
|
||||
|
||||
@interface InAppProductsManager : NSObject <SKProductsRequestDelegate, SKPaymentTransactionObserver>
|
||||
@interface InAppProductsManager : NSObject <SKProductsRequestDelegate, SKPaymentTransactionObserver> {
|
||||
NSString *latestReceiptMD5;
|
||||
}
|
||||
|
||||
// startup status, manager is not ready yet.
|
||||
#define IAPNotReadyYet @"IAPNotReadyYet"
|
||||
|
|
|
|||
|
|
@ -152,13 +152,11 @@ NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotificati
|
|||
}
|
||||
|
||||
- (void)checkReceipt: (SKPaymentTransaction*)transaction {
|
||||
NSData *receiptData = nil;
|
||||
NSString *receiptBase64 = nil;
|
||||
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
|
||||
|
||||
// Test whether the receipt is present at the above URL
|
||||
if([[NSFileManager defaultManager] fileExistsAtPath:[receiptURL path]]) {
|
||||
receiptData = [NSData dataWithContentsOfURL:receiptURL];
|
||||
LOGI(@"Found appstore receipt");
|
||||
} else {
|
||||
if(![[NSFileManager defaultManager] fileExistsAtPath:[receiptURL path]]) {
|
||||
// We are probably in sandbox environment, trying to retrieve it...
|
||||
SKRequest* req = [[SKReceiptRefreshRequest alloc] init];
|
||||
LOGI(@"Receipt not found yet, trying to retrieve it...");
|
||||
|
|
@ -167,19 +165,28 @@ NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotificati
|
|||
return;
|
||||
}
|
||||
|
||||
// We must validate the receipt on our server
|
||||
NSURL *URL = [NSURL URLWithString:[[LinphoneManager instance] lpConfigStringForKey:@"receipt_validation_url" forSection:@"in_app_purchase"]];
|
||||
LOGI(@"Found appstore receipt");
|
||||
receiptBase64 = [[NSData dataWithContentsOfURL:receiptURL] base64EncodedStringWithOptions:0];
|
||||
//only check the receipt if it has changed
|
||||
if (latestReceiptMD5 == nil || ! [latestReceiptMD5 isEqualToString:[receiptBase64 md5]]) {
|
||||
// We must validate the receipt on our server
|
||||
NSURL *URL = [NSURL URLWithString:[[LinphoneManager instance] lpConfigStringForKey:@"receipt_validation_url" forSection:@"in_app_purchase"]];
|
||||
|
||||
XMLRPCRequest *request = [[XMLRPCRequest alloc] initWithURL: URL];
|
||||
[request setMethod: @"get_expiration_date" withParameters:[NSArray arrayWithObjects:
|
||||
[receiptData base64EncodedStringWithOptions:0],
|
||||
@"",
|
||||
@"apple",
|
||||
nil]];
|
||||
XMLRPCConnectionManager *manager = [XMLRPCConnectionManager sharedManager];
|
||||
[manager spawnConnectionWithXMLRPCRequest: request delegate: self.xmlrpc];
|
||||
LOGE(@"XMLRPC query %@: %@", [request method], [request body]);
|
||||
[request release];
|
||||
XMLRPCRequest *request = [[XMLRPCRequest alloc] initWithURL: URL];
|
||||
[request setMethod: @"get_expiration_date" withParameters:[NSArray arrayWithObjects:
|
||||
receiptBase64,
|
||||
@"",
|
||||
@"apple",
|
||||
nil]];
|
||||
latestReceiptMD5 = [[receiptBase64 md5] retain];
|
||||
|
||||
XMLRPCConnectionManager *manager = [XMLRPCConnectionManager sharedManager];
|
||||
[manager spawnConnectionWithXMLRPCRequest: request delegate: self.xmlrpc];
|
||||
LOGI(@"XMLRPC query %@: %@", [request method], [request body]);
|
||||
[request release];
|
||||
} else {
|
||||
LOGW(@"Skipping receipt check, it has already been done!");
|
||||
}
|
||||
}
|
||||
|
||||
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
|
||||
|
|
@ -239,7 +246,7 @@ NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotificati
|
|||
}
|
||||
|
||||
- (void)retrievePurchases {
|
||||
LOGE(@"todo");//[self checkReceipt:nil];
|
||||
[self checkReceipt:nil];
|
||||
}
|
||||
|
||||
- (void)XMLRPCRequest:(XMLRPCRequest *)request didReceiveResponse:(XMLRPCResponse *)response {
|
||||
|
|
@ -259,11 +266,14 @@ NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotificati
|
|||
//Don't handle if not object: HTTP/Communication Error
|
||||
if([[request method] isEqualToString:@"get_expiration_date"]) {
|
||||
if([response object] == [NSNumber numberWithInt:1]) {
|
||||
LOGE(@"Todo: parse the response");
|
||||
// [_productsIDPurchased addObject:@"test.auto_renew_7days"];
|
||||
[self postNotificationforStatus:IAPReceiptSucceeded];
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
latestReceiptMD5 = nil;
|
||||
[self postNotificationforStatus:IAPReceiptFailed];
|
||||
}
|
||||
|
||||
|
|
@ -278,7 +288,7 @@ NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotificati
|
|||
// [errorView show];
|
||||
// [errorView release];
|
||||
// [waitView setHidden:true];
|
||||
|
||||
latestReceiptMD5 = nil;
|
||||
[self postNotificationforStatus:IAPReceiptFailed];
|
||||
}
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -1370,7 +1370,7 @@ static LinphoneCoreVTable linphonec_vtable = {
|
|||
}
|
||||
linphone_core_enable_video(theLinphoneCore, FALSE, FALSE);
|
||||
}
|
||||
// Retrieve InApp purchases
|
||||
// Query our in-app server when core is ready in order to retrieve InApp purchases
|
||||
[_iapManager retrievePurchases];
|
||||
|
||||
LOGW(@"Linphone [%s] started on [%s]", linphone_core_get_version(), [[UIDevice currentDevice].model cStringUsingEncoding:[NSString defaultCStringEncoding]]);
|
||||
|
|
|
|||
|
|
@ -69,3 +69,9 @@ typedef enum _LinphoneLoggerSeverity {
|
|||
#define LOGF(...) LOGV(LinphoneLoggerFatal, __VA_ARGS__)
|
||||
|
||||
#endif
|
||||
|
||||
@interface NSString(md5)
|
||||
|
||||
- (NSString *)md5;
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -231,5 +231,22 @@
|
|||
return([NSString stringWithFormat:@"%1.1f GB",floatSize]);
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSString(md5)
|
||||
|
||||
#import <CommonCrypto/CommonDigest.h>
|
||||
|
||||
- (NSString *)md5 {
|
||||
const char *ptr = [self UTF8String];
|
||||
unsigned char md5Buffer[CC_MD5_DIGEST_LENGTH];
|
||||
CC_MD5(ptr, strlen(ptr), md5Buffer);
|
||||
NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
|
||||
for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) {
|
||||
[output appendFormat:@"%02x",md5Buffer[i]];
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -20,6 +20,7 @@
|
|||
#import <UIKit/UIKit.h>
|
||||
#import <XMLRPCConnectionDelegate.h>
|
||||
#import "UICompositeViewController.h"
|
||||
#import "LinphoneUI/UILinphoneButton.h"
|
||||
|
||||
@interface WizardViewController : TPMultiLayoutViewController
|
||||
<UITextFieldDelegate,
|
||||
|
|
@ -53,6 +54,8 @@
|
|||
@property (nonatomic, retain) IBOutlet UIButton *connectAccountButton;
|
||||
@property (nonatomic, retain) IBOutlet UIButton *externalAccountButton;
|
||||
@property (retain, nonatomic) IBOutlet UIButton *remoteProvisioningButton;
|
||||
@property (retain, nonatomic) IBOutlet UILinphoneButton *registerButton;
|
||||
@property (retain, nonatomic) IBOutlet UILinphoneButton *purchaseButton;
|
||||
|
||||
@property (retain, nonatomic) IBOutlet UITextField *provisionedUsername;
|
||||
@property (retain, nonatomic) IBOutlet UITextField *provisionedPassword;
|
||||
|
|
|
|||
|
|
@ -114,6 +114,8 @@ typedef enum _ViewElement {
|
|||
[provisionedPassword release];
|
||||
[provisionedDomain release];
|
||||
[_transportChooser release];
|
||||
[_purchaseButton release];
|
||||
[_registerButton release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
|
@ -203,6 +205,10 @@ static UICompositeViewDescription *compositeDescription = nil;
|
|||
[LinphoneUtils adjustFontSize:validateAccountView mult:2.22f];
|
||||
[LinphoneUtils adjustFontSize:provisionedAccountView mult:2.22f];
|
||||
}
|
||||
|
||||
BOOL mustPurchaseNewAccount = ([[LinphoneManager instance] lpConfigStringForKey:@"paid_account_id" forSection:@"in_app_purchase"] != nil);
|
||||
_registerButton.hidden = mustPurchaseNewAccount;
|
||||
_purchaseButton.hidden = !mustPurchaseNewAccount;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -731,29 +737,7 @@ static UICompositeViewDescription *compositeDescription = nil;
|
|||
[remoteInput release];
|
||||
}
|
||||
|
||||
- (void)inAppPurchaseNotification: (NSNotification*)notification {
|
||||
InAppProductsManager *iapm = [[LinphoneManager instance] iapManager];
|
||||
if ([iapm isPurchasedWithID:[[LinphoneManager instance] lpConfigStringForKey:@"paid_account_id" forSection:@"in_app_purchase"]]) {
|
||||
[self onPurchaseAccountClick:self];
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)onPurchaseAccountClick:(id)sender {
|
||||
InAppProductsManager *iapm = [[LinphoneManager instance] iapManager];
|
||||
//if has already purchased, continue
|
||||
if ([iapm isPurchasedWithID:[[LinphoneManager instance] lpConfigStringForKey:@"paid_account_id" forSection:@"in_app_purchase"]]) {
|
||||
NSString *username = [WizardViewController findTextField:ViewElement_Username view:contentView].text;
|
||||
NSString *password = [WizardViewController findTextField:ViewElement_Password view:contentView].text;
|
||||
NSString *domain = [WizardViewController findTextField:ViewElement_Domain view:contentView].text;
|
||||
NSString *transport = [self.transportChooser titleForSegmentAtIndex:self.transportChooser.selectedSegmentIndex];
|
||||
|
||||
[self verificationSignInWithUsername:username password:password domain:domain withTransport:transport];
|
||||
} else {
|
||||
[iapm purchaseWithID: [[LinphoneManager instance] lpConfigStringForKey:@"paid_account_id" forSection:@"in_app_purchase"]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) verificationSignInWithUsername:(NSString*)username password:(NSString*)password domain:(NSString*)domain withTransport:(NSString*)transport {
|
||||
- (BOOL) verificationWithUsername:(NSString*)username password:(NSString*)password domain:(NSString*)domain withTransport:(NSString*)transport {
|
||||
NSMutableString *errors = [NSMutableString string];
|
||||
if ([username length] == 0) {
|
||||
[errors appendString:[NSString stringWithFormat:NSLocalizedString(@"Please enter a valid username.\n", nil)]];
|
||||
|
|
@ -771,7 +755,12 @@ static UICompositeViewDescription *compositeDescription = nil;
|
|||
otherButtonTitles:nil,nil];
|
||||
[errorView show];
|
||||
[errorView release];
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
- (void) verificationSignInWithUsername:(NSString*)username password:(NSString*)password domain:(NSString*)domain withTransport:(NSString*)transport {
|
||||
if ([self verificationWithUsername:username password:password domain:domain withTransport:transport]) {
|
||||
[waitView setHidden:false];
|
||||
if ([LinphoneManager instance].connectivity == none) {
|
||||
DTAlertView *alert = [[DTAlertView alloc] initWithTitle:NSLocalizedString(@"No connectivity", nil)
|
||||
|
|
@ -811,44 +800,50 @@ static UICompositeViewDescription *compositeDescription = nil;
|
|||
[self verificationSignInWithUsername:username password:password domain:nil withTransport:nil];
|
||||
}
|
||||
|
||||
- (BOOL)verificationRegisterWithUsername:(NSString*)username password:(NSString*)password password2:(NSString*)password2 email:(NSString*)email {
|
||||
NSMutableString *errors = [NSMutableString string];
|
||||
NSInteger username_length = [[LinphoneManager instance] lpConfigIntForKey:@"username_length" forSection:@"wizard"];
|
||||
NSInteger password_length = [[LinphoneManager instance] lpConfigIntForKey:@"password_length" forSection:@"wizard"];
|
||||
|
||||
if ([username length] < username_length) {
|
||||
[errors appendString:[NSString stringWithFormat:NSLocalizedString(@"The username is too short (minimum %d characters).\n", nil), username_length]];
|
||||
}
|
||||
|
||||
if ([password length] < password_length) {
|
||||
[errors appendString:[NSString stringWithFormat:NSLocalizedString(@"The password is too short (minimum %d characters).\n", nil), password_length]];
|
||||
}
|
||||
|
||||
if (![password2 isEqualToString:password]) {
|
||||
[errors appendString:NSLocalizedString(@"The passwords are different.\n", nil)];
|
||||
}
|
||||
|
||||
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", @".+@.+\\.[A-Za-z]{2}[A-Za-z]*"];
|
||||
if(![emailTest evaluateWithObject:email]) {
|
||||
[errors appendString:NSLocalizedString(@"The email is invalid.\n", nil)];
|
||||
}
|
||||
|
||||
if([errors length]) {
|
||||
UIAlertView* errorView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Check error(s)",nil)
|
||||
message:[errors substringWithRange:NSMakeRange(0, [errors length] - 1)]
|
||||
delegate:nil
|
||||
cancelButtonTitle:NSLocalizedString(@"Continue",nil)
|
||||
otherButtonTitles:nil,nil];
|
||||
[errorView show];
|
||||
[errorView release];
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
- (IBAction)onRegisterClick:(id)sender {
|
||||
UITextField* username_tf = [WizardViewController findTextField:ViewElement_Username view:contentView];
|
||||
NSString *username = username_tf.text;
|
||||
NSString *password = [WizardViewController findTextField:ViewElement_Password view:contentView].text;
|
||||
NSString *password2 = [WizardViewController findTextField:ViewElement_Password2 view:contentView].text;
|
||||
NSString *email = [WizardViewController findTextField:ViewElement_Email view:contentView].text;
|
||||
NSMutableString *errors = [NSMutableString string];
|
||||
|
||||
NSInteger username_length = [[LinphoneManager instance] lpConfigIntForKey:@"username_length" forSection:@"wizard"];
|
||||
NSInteger password_length = [[LinphoneManager instance] lpConfigIntForKey:@"password_length" forSection:@"wizard"];
|
||||
|
||||
if ([username length] < username_length) {
|
||||
[errors appendString:[NSString stringWithFormat:NSLocalizedString(@"The username is too short (minimum %d characters).\n", nil), username_length]];
|
||||
}
|
||||
|
||||
if ([password length] < password_length) {
|
||||
[errors appendString:[NSString stringWithFormat:NSLocalizedString(@"The password is too short (minimum %d characters).\n", nil), password_length]];
|
||||
}
|
||||
|
||||
if (![password2 isEqualToString:password]) {
|
||||
[errors appendString:NSLocalizedString(@"The passwords are different.\n", nil)];
|
||||
}
|
||||
|
||||
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", @".+@.+\\.[A-Za-z]{2}[A-Za-z]*"];
|
||||
if(![emailTest evaluateWithObject:email]) {
|
||||
[errors appendString:NSLocalizedString(@"The email is invalid.\n", nil)];
|
||||
}
|
||||
|
||||
if([errors length]) {
|
||||
UIAlertView* errorView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Check error(s)",nil)
|
||||
message:[errors substringWithRange:NSMakeRange(0, [errors length] - 1)]
|
||||
delegate:nil
|
||||
cancelButtonTitle:NSLocalizedString(@"Continue",nil)
|
||||
otherButtonTitles:nil,nil];
|
||||
[errorView show];
|
||||
[errorView release];
|
||||
|
||||
} else {
|
||||
if ([self verificationRegisterWithUsername:username password:password password2:password2 email:email]) {
|
||||
username = [username lowercaseString];
|
||||
[username_tf setText:username];
|
||||
NSString *identity = [self identityFromUsername:username];
|
||||
|
|
@ -856,6 +851,42 @@ static UICompositeViewDescription *compositeDescription = nil;
|
|||
}
|
||||
}
|
||||
|
||||
- (void)inAppPurchaseNotification: (NSNotification*)notification {
|
||||
InAppProductsManager *iapm = [[LinphoneManager instance] iapManager];
|
||||
BOOL wasWaitingForInApp = (currentView == createAccountView) && ![waitView isHidden];
|
||||
[waitView setHidden:true];
|
||||
|
||||
//now that the purchase is made, let's create the account.
|
||||
if (wasWaitingForInApp) {
|
||||
if ([iapm isPurchasedWithID:[[LinphoneManager instance] lpConfigStringForKey:@"paid_account_id" forSection:@"in_app_purchase"]]) {
|
||||
[waitView setHidden:true];
|
||||
[self onPurchaseAccountClick:self];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)onPurchaseAccountClick:(id)sender {
|
||||
UITextField* username_tf = [WizardViewController findTextField:ViewElement_Username view:contentView];
|
||||
NSString *username = username_tf.text;
|
||||
NSString *password = [WizardViewController findTextField:ViewElement_Password view:contentView].text;
|
||||
NSString *password2 = [WizardViewController findTextField:ViewElement_Password2 view:contentView].text;
|
||||
NSString *email = [WizardViewController findTextField:ViewElement_Email view:contentView].text;
|
||||
|
||||
if ([self verificationRegisterWithUsername:username password:password password2:password2 email:email]) {
|
||||
InAppProductsManager *iapm = [[LinphoneManager instance] iapManager];
|
||||
//if has already purchased, continue
|
||||
if ([iapm isPurchasedWithID:[[LinphoneManager instance] lpConfigStringForKey:@"paid_account_id" forSection:@"in_app_purchase"]]) {
|
||||
username = [username lowercaseString];
|
||||
[username_tf setText:username];
|
||||
NSString *identity = [self identityFromUsername:username];
|
||||
[self checkUserExist:identity];
|
||||
} else {
|
||||
[waitView setHidden:false];
|
||||
[iapm purchaseWithID: [[LinphoneManager instance] lpConfigStringForKey:@"paid_account_id" forSection:@"in_app_purchase"]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)onProvisionedLoginClick:(id)sender {
|
||||
NSString *username = provisionedUsername.text;
|
||||
NSString *password = provisionedPassword.text;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue