Helcim Logo Support & Tutorials

© Copyright 2006-2018 Helcim Inc.

All Rights Reserved.

POS Hybrid Integration » iOS »

iOS App Sample


#import "ViewController.h"
#import "hcmTerminal.h"


@interface ViewController (){
    
    hcmTerminal *terminalTest;

}
@property (strong, nonatomic) IBOutlet UITextField *txtAmount;
@property (strong, nonatomic) IBOutlet UITextField *txtClerkId;
@property (strong, nonatomic) IBOutlet UITextField *txtInvNum;
@property (strong, nonatomic) IBOutlet UITextView *txtview;
@property (strong, nonatomic) NSString *terminalIp;
@property  NSInteger *terminalPort;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    // INIZALIZE HCMTERMINAL
    terminalTest = [[hcmTerminal alloc] init];

    
}

- (IBAction)btnSale:(id)sender {
    
    // SET IP AND PORT
    terminalTest.terminalIp = self.terminalIp;
    terminalTest.terminalPort = self.terminalPort;
    
    // SET EXTRAS
    terminalTest.amount = [self.txtAmount.text intValue];
    terminalTest.clerkId = [self.txtClerkId.text intValue];
    terminalTest.invoiceNumber = [self.txtInvNum.text intValue];
    
    // PROCESS PURCHASE
    [terminalTest hcmPurchase];
    
    // START TIMER
    NSTimer *logTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(onTick:) userInfo:nil repeats:YES];
    
    
}


- (IBAction)btnTestCon:(id)sender {
    
    // SET IP AND PORT
    terminalTest.terminalIp = self.terminalIp;
    terminalTest.terminalPort = self.terminalPort;

    // TEST CONNECTION
    [terminalTest hcmTestConnection];
    
    // START TIMER
    NSTimer *logTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(onTick:) userInfo:nil repeats:YES];

}


-(void)onTick:(NSTimer *)timer{
    
    // MAKE SURE NOT NULL
    if(terminalTest.connectionLog != nil){
        
        // CHECK IF DATA
        if(terminalTest.connectionLog.length > 1){
            
            // SET TEXT
            self.txtview.text = [self.txtview.text stringByAppendingString:terminalTest.connectionLog];
            
            if([terminalTest.connectionLog containsString:@"Ended Connection"]){
                
                [timer invalidate];
                
            }
            
            
            // CLEAR LOG
            terminalTest.connectionLog = @" ";
            
            // CHECK FOR RESPONSE MESSAGE
            if(terminalTest.responseMessage != nil){
                
                self.txtview.text = [self.txtview.text stringByAppendingString:[NSString stringWithFormat:@"\n\n%@",terminalTest.responseMessage]];
                
            }
            
        }
         
    }
    
}


- (IBAction)btnSettings:(id)sender {
    
    // CALL FUNCTION TO SHOW ALERT
    [self showalert];
    
}


-(void)showalert{
    
    // CREATE ALERT
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Settings"
                                                        message:@"Enter Ip and Port"
                                                        delegate:self
                                                        cancelButtonTitle:@"Cancel"
                                                        otherButtonTitles:@"Set", nil];
    
    // SETTINGS FOR INPUT 1
    alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
    UITextField * alertTextField1 = [alert textFieldAtIndex:0];
    alertTextField1.keyboardType = UIKeyboardTypeDefault;
    alertTextField1.placeholder = @"Ip";
    
    // SETTINGS FOR INPUT 2
    UITextField * alertTextField2 = [alert textFieldAtIndex:1];
    alertTextField2.keyboardType = UIKeyboardTypeDefault;
    alertTextField2.placeholder = @"Port";
    alertTextField2.secureTextEntry=NO;
    
    // SHOW POPUP
    [alert show];

}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    
    // SAVE SETTINGS FROM POPUP PAGE
    self.terminalIp = [alertView textFieldAtIndex:0].text;
    self.terminalPort = [[alertView textFieldAtIndex:1].text integerValue];

}

@end