Thursday 19 July 2012

URL implementation User Registration Form in Xcode

.h File

#import <UIKit/UIKit.h>

@interface RootViewController : UIViewController
{
    IBOutlet UIActivityIndicatorView *activityView;
    IBOutlet UILabel *lbl_device;
    NSString *content;
}

-(void)updateCounter:(NSTimer *)theTimer;
-(void)countdownTimer;

@property(nonatomic,retain)  UIActivityIndicatorView *activityView;

@end



.m File

#import "RootViewController.h"
#import "screen2.h"
#import "profile.h"

@implementation RootViewController
@synthesize activityView;

NSTimer *timer;
int hours, minutes, seconds;
int secondsLeft;


- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationController.navigationBarHidden=YES;
    secondsLeft = 5;
    [self countdownTimer];
}

- (void)updateCounter:(NSTimer *)theTimer
{
    if(secondsLeft > 0 )
    {
        secondsLeft-- ;
        hours = secondsLeft / 3600;
        minutes = (secondsLeft % 3600) / 60;
        seconds = (secondsLeft %3600) % 60;
       // myCounterLabel.text = [NSString stringWithFormat:@":%02d",seconds];
     
        if (secondsLeft==0)
        {
         
            UIDevice *myDevice = [UIDevice currentDevice];
            NSString *deviceUDID = [myDevice uniqueIdentifier];
            NSLog(@"%@",deviceUDID);
            lbl_device.text=deviceUDID;
            self.navigationController.navigationBarHidden=YES;
         
            NSString *stringURL =[NSString stringWithFormat: @"http://www.support.iwedplanner.com/KnowledgeBowl/KnowBowl_Login.aspx?UD_ID=%@",deviceUDID,nil];
            NSLog(stringURL);
            NSURL *url = [NSURL URLWithString:stringURL];
            content=[NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:NULL];
            NSLog(content);
            NSString* result = content;
            NSArray* components = [result componentsSeparatedByString:@"/n"];
         
         
            NSString* name1 = [components objectAtIndex:1];
            NSString* udid1 = [components objectAtIndex:2];
            NSLog(@"name is %@",name1);
            NSLog(@"device id is %@",udid1);
                       if([udid1 isEqualToString:@"UD_IDExist"])
             
            {
             // Check challenge availability
             
                NSString *stringURL =[NSString stringWithFormat: @"http://www.support.iwedplanner.com/KnowledgeBowl/KnowBowl_UserAvailability.aspx?UserName2=%@",name1,nil];
                NSLog(stringURL);
                NSURL *url = [NSURL URLWithString:stringURL];
                //NSLog(url);
                content=[NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:NULL];
                if ([content isEqualToString:@"|UserName2 Not Availblity|"])
                {
                    screen2 *main=[[screen2 alloc]init];
                   [self.navigationController pushViewController:main animated:YES];
                }
                else
                {
                    User2Response *u2_play=[[User2Response alloc]init];
                    [self.navigationController pushViewController:u2_play animated:YES];
                }              
            }
            else
            {
                profile *prof1=[[profile alloc]init];
                [self.navigationController pushViewController:prof1 animated:YES];
            }
         

        }
    }
 
}


-(void)countdownTimer
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateCounter:) userInfo:nil repeats:YES];
    [pool release];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end

No comments: