Developer Area

Changeset 672

Show
Ignore:
Timestamp:
01/19/10 15:57:59 (8 weeks ago)
Author:
henri
Message:

Fix for case when autoprovisioning not possible and user only know the TelHosting? URL

Location:
apps/iphone/my.tel/trunk/Classes
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • apps/iphone/my.tel/trunk/Classes/AccountEditController.h

    r593 r672  
    99#import <UIKit/UIKit.h> 
    1010#import "MyTelConnect.h" 
    11 #import "DnsResolver.h" 
     11#import "TextFieldCell.h" 
     12#import "AlertRenameView.h" 
    1213 
    13 #import "TextFieldCell.h" 
    14  
    15 @interface AccountEditController : UITableViewController <UITextFieldDelegate> { 
     14@interface AccountEditController : UITableViewController <UITextFieldDelegate, UIAlertViewDelegate> { 
    1615        TextFieldCell *cellAccountLabel;                // user-created label for the account (optional) 
    1716        TextFieldCell *cellDomainName;                  // name of a domain in the account (any domain in the account will do) 
     
    2524- (void)didPressSave; 
    2625- (void)didPressCancel; 
    27 - (NSString *)apiUrlForDomain:(NSString *)aDomain withError:(NSError **)error; 
    2826 
    2927@property (nonatomic, retain) IBOutlet TextFieldCell *cellAccountLabel; 
  • apps/iphone/my.tel/trunk/Classes/AccountEditController.m

    r667 r672  
    168168                        break;           
    169169                case 2: 
    170                         return @"There should be no need to modify this section."; 
     170                        return @"Modify items in this section only if necessary."; 
    171171                        break;           
    172172                default: 
     
    210210                case 2: 
    211211                        cell = cellApiRootUrl; 
    212                         cell.textLabel.text = @"API Root URL"; 
     212                        cell.textLabel.text = @"TelHosting API URL"; 
    213213                        cell.textField.placeholder = @"http://telhosting/g2/json"; 
    214214                        break; 
     
    282282        if (!self.apiRootUrl || [self.apiRootUrl isEqualToString:@""]) { 
    283283                NSError *loginError = nil;       
    284                 self.apiRootUrl = [self apiUrlForDomain:self.domainName withError:&loginError]; 
    285         } 
    286  
     284                self.apiRootUrl = [[MyTelConnect sharedInstance] apiUrlForDomain:self.domainName withError:&loginError]; 
     285                if (loginError != nil) { 
     286                        // Can't get autoprovision, ask for .tel provider URL 
     287                        NSString *alertTitle = [NSString stringWithFormat:@"Unknown TelHosting URL for %@", self.domainName]; 
     288                        NSMutableString *fullMessage = [NSMutableString stringWithString:@"Enter the TelHosting URL given by your .tel provider"]; 
     289                        AlertRenameView *alert = [[AlertRenameView alloc] initWithTitle:alertTitle 
     290                                                                                                                                        message:fullMessage 
     291                                                                                                                                   delegate:self 
     292                                                                                                                  cancelButtonTitle:@"Cancel" 
     293                                                                                                                  otherButtonTitles:@"OK", nil]; 
     294                        alert.uiStringField.minimumFontSize = 14.0f; 
     295                        alert.uiStringField.font = [alert.uiStringField.font fontWithSize:14.0f]; 
     296                        alert.uiStringField.placeholder = @"https://telhosting.provider.com"; 
     297                        [alert show]; 
     298                        [alert release]; 
     299                        self.navigationItem.rightBarButtonItem = origButton; 
     300                        [origButton release]; 
     301                        return; 
     302                }                        
     303        } 
     304        // All was well 
    287305        [self.delegate dataDidChangeInController:self]; 
    288         self.navigationItem.rightBarButtonItem = origButton; 
    289         [origButton release]; 
    290306        [self.navigationController popViewControllerAnimated:YES]; 
    291307} 
     
    295311} 
    296312 
    297 - (NSString *)apiUrlForDomain:(NSString *)aDomain withError:(NSError **)error { 
    298         if (!aDomain) 
    299                 return nil; 
    300         // try to autoprovision apiRootUrl 
    301         [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; 
    302         NSMutableArray *naptrArray = [NSMutableArray arrayWithCapacity:1]; 
    303         NSString *autoProvisionDomain = [@"_https._nsp._apps." stringByAppendingString:aDomain]; 
    304         DnsResolver *resolver =[[DnsResolver alloc] init]; 
    305         [resolver getNAPTRForTel:autoProvisionDomain inArray:naptrArray withError:error]; 
    306         if ([naptrArray count] == 0) { 
    307                 // couldn't find anything, try in http mode 
    308                 NSString *autoProvisionDomainHttp = [@"_http._nsp._apps." stringByAppendingString:aDomain]; 
    309                 [resolver getNAPTRForTel:autoProvisionDomainHttp inArray:naptrArray withError:error]; 
    310         } 
    311         [resolver release]; 
    312         [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; 
    313         if ([naptrArray count] > 0) { 
    314                 // we have autoprovision of the Telhosting URL, let's tweak it to get the JSON API 
    315                 RecordNaptr *theRec = [naptrArray objectAtIndex:0]; 
    316                 return ([theRec.uriContent stringByAppendingString:@"/g2/json"]); 
    317         }        
    318         // Still found nothing, no autoprovisioning possible 
    319         return @""; 
     313#pragma mark - 
     314#pragma mark UIAlertViewDelegate methods 
     315 
     316- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex { 
     317        if (buttonIndex == alertView.cancelButtonIndex) { 
     318                return; 
     319        } 
     320        NSMutableString *apiRoot = [NSMutableString stringWithString:((AlertRenameView *)alertView).uiStringField.text]; 
     321        if (apiRoot == nil) { 
     322                [apiRoot setString:@""]; 
     323        } 
     324        if (![apiRoot hasPrefix:@"http"]) { 
     325                [apiRoot insertString:@"https://" atIndex:0]; 
     326        } 
     327        if (![apiRoot hasSuffix:@"/g2/json"]) { 
     328                [apiRoot appendString:@"/g2/json"]; 
     329        } 
     330        self.apiRootUrl = ((AlertRenameView *)alertView).uiStringField.text = apiRoot; 
    320331} 
    321332 
  • apps/iphone/my.tel/trunk/Classes/AlertRenameView.m

    r593 r672  
    1313#define kARTextFieldDiff 50 
    1414// Height of text field 
    15 #define kARTextFieldHeight 32 
     15#define kARTextFieldHeight 28 
     16// Height of bottom buttons of UIAlertView, including margins 
     17#define kARButtonsHeight 75 
    1618 
    1719@implementation AlertRenameView 
     
    3234                theField.borderStyle = UITextBorderStyleRoundedRect; 
    3335                theField.minimumFontSize = 16; 
     36                theField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 
    3437                theField.clearButtonMode = UITextFieldViewModeAlways; 
    3538                theField.autocorrectionType = UITextAutocorrectionTypeNo; 
     
    3841                uiStringField = theField; 
    3942                [self addSubview:uiStringField]; 
    40                  
    41                 self.message = @"\n\n";         // No messages here, only space for the entry field 
    4243    } 
    4344    return self; 
     45} 
     46 
     47- (void)setMessage:(NSString *)aMessage { 
     48        // add space for the entry field. Height depends on whether there's text or not 
     49        if ((aMessage != nil) && (aMessage != @"\n\n") && ([aMessage length] > 0)) { 
     50                [super setMessage:[aMessage stringByAppendingString:@"\n\n\n"]]; 
     51        } else { 
     52                [super setMessage:@"\n\n"]; 
     53        } 
    4454} 
    4555 
     
    4959    CGRect textRect = boundsRect; 
    5060        textRect.size = CGSizeMake(rect.size.width - kARTextFieldDiff, kARTextFieldHeight); 
    51         textRect = CGRectOffset(textRect, kARTextFieldDiff/2 , kARTextFieldHeight+18); 
     61        textRect = CGRectOffset(textRect, kARTextFieldDiff/2 , rect.size.height - (kARTextFieldHeight + kARButtonsHeight)); 
    5262        uiStringField.frame = textRect; 
    5363} 
     
    6676} 
    6777- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { 
    68         self.frame = CGRectOffset(self.frame, 0, -(48+kARTextFieldHeight)); 
     78        self.frame = CGRectOffset(self.frame, 0, -(52+kARTextFieldHeight)); 
    6979        return YES; 
    7080} 
    7181- (void)textFieldDidEndEditing:(UITextField *)textField { 
    72         self.frame = CGRectOffset(self.frame, 0, 48+kARTextFieldHeight); 
     82        self.frame = CGRectOffset(self.frame, 0, 52+kARTextFieldHeight); 
    7383} 
    7484@end 
  • apps/iphone/my.tel/trunk/Classes/MyTelConnect.h

    r612 r672  
    1111#import "JSON/JSON.h" 
    1212#import "Profile.h" 
     13#import "DnsResolver.h" 
     14 
     15enum MyTelConnect_enum_status { 
     16        MYTELCONNECT_STATUS_NXAPIURL 
     17}; 
    1318 
    1419// Shorthand for getting localized strings 
     
    4449 
    4550- (NSString *)topDomainFromDomain:(NSString *)aDomain; 
     51- (NSString *)apiUrlForDomain:(NSString *)aDomain withError:(NSError **)error; 
    4652 
    4753@property (nonatomic, retain) NSArray *profilesInDomain; 
  • apps/iphone/my.tel/trunk/Classes/MyTelConnect.m

    r639 r672  
    103103} 
    104104 
     105- (NSString *)apiUrlForDomain:(NSString *)aDomain withError:(NSError **)error { 
     106        if (!aDomain) 
     107                return nil; 
     108        // try to autoprovision apiRootUrl 
     109        [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; 
     110        NSMutableArray *naptrArray = [NSMutableArray arrayWithCapacity:1]; 
     111        NSString *autoProvisionDomain = [@"_https._nsp._apps." stringByAppendingString:aDomain]; 
     112        DnsResolver *resolver =[[DnsResolver alloc] init]; 
     113        [resolver getNAPTRForTel:autoProvisionDomain inArray:naptrArray withError:error]; 
     114        if ([naptrArray count] == 0) { 
     115                // couldn't find anything, try in http mode 
     116                NSString *autoProvisionDomainHttp = [@"_http._nsp._apps." stringByAppendingString:aDomain]; 
     117                [resolver getNAPTRForTel:autoProvisionDomainHttp inArray:naptrArray withError:error]; 
     118        } 
     119        [resolver release]; 
     120        [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; 
     121        if ([naptrArray count] > 0) { 
     122                // we have autoprovision of the Telhosting URL, let's tweak it to get the JSON API 
     123                RecordNaptr *theRec = [naptrArray objectAtIndex:0]; 
     124                return ([theRec.uriContent stringByAppendingString:@"/g2/json"]); 
     125        }        
     126        // Still found nothing, no autoprovisioning possible 
     127        NSDictionary *dict = [NSDictionary dictionaryWithObject:@"Please verify that your domain name is correct" 
     128                                                                                                         forKey:NSLocalizedDescriptionKey]; 
     129 
     130        if (error != NULL) 
     131                *error = [NSError errorWithDomain:@"my.tel" code:MYTELCONNECT_STATUS_NXAPIURL userInfo:dict]; 
     132        return @""; 
     133} 
     134 
    105135#pragma mark - 
    106136#pragma mark singleton object methods 
Telnic
Search This Site
Partners
Neustar
ICANN
Main site | WHOIS | Sell .tel | FAQ | Archived Site | About Telnic | Contact Us