Sunday, July 17, 2016

Check for internet Connection- with UIAlertview -Ios

- (void)viewDidLoad {
    [super viewDidLoad];
    
    Reachability *networkReachability = [Reachability reachabilityForInternetConnection];
    NetworkStatus networkStatus = [networkReachability currentReachabilityStatus];
    if (networkStatus == NotReachable) {
        // NSLog(@"There IS NO internet connection");
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Opps!!"
                                                        message:@"you may need to check your network Conenction.."
                                                       delegate:self
                                              cancelButtonTitle:@"Settings"
                                              otherButtonTitles:@"Cancel",nil];
        [alert show];
        
        
        
        
        
    } else {
        
        loadingIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(100, 100, 50,50)];
        [loadingIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
        [loadingIndicator setHidesWhenStopped:YES];

        [self registerCells];
        [self loadData];
        
    }
    
    // Do any additional setup after loading the view.
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    // the user clicked OK
    if (buttonIndex == 0) {
        NSURL*url=[NSURL URLWithString:@"prefs:root=WIFI"];
        [[UIApplication sharedApplication] openURL:url];
        [self.navigationController popViewControllerAnimated:YES];
        
    }
    if (buttonIndex == 1) {
        [self.navigationController popViewControllerAnimated:YES];
        
    }

}

Compare Two dates- ios


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
    
    NSDate *todayDate = [NSDate date]; // get today date
    NSDateFormatter *dateFormatter2 = [[NSDateFormatter alloc] init]; // here we create      NSDateFormatter object for change the Format of date..
    [dateFormatter2 setDateFormat:@"yyyy-MM-dd hh:mm:ss Z"]; //Here we can set the format which we need
    NSString *convertedDateString = [dateFormatter2 stringFromDate:todayDate];// here convert date in
  NSLog(@"Today formatted date is %@",convertedDateString);
    
    
    
    
    
    NSString *getTokon_Time1 = @"2016-07-20 03:19:05 +0000";
   // NSString *getTokon_Time2 = @"2016-07-31 03:18:05 +0000";
    NSDateFormatter *dateFormatter=[NSDateFormatter new];
    [dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm:ss Z"];
    NSDate *tokonExpireDate1=[dateFormatter dateFromString:getTokon_Time1];
    NSDate *tokonExpireDate2=[dateFormatter dateFromString:convertedDateString];
    BOOL isTokonValid = [self dateComparision:tokonExpireDate1 andDate2:tokonExpireDate2];
    
    
    // Do any additional setup after loading the view.
}

-(BOOL)dateComparision:(NSDate*)date1 andDate2:(NSDate*)date2{
    
    BOOL isTokonValid;
    
    if ([date1 compare:date2] == NSOrderedDescending) {
        NSLog(@"date1 is later than date2");
        
        
        
        isTokonValid = YES;
        
        
        
    } else if ([date1 compare:date2] == NSOrderedAscending) {
        NSLog(@"date1 is earlier than date2");
        isTokonValid = NO;
        
        
      
    } else {
        NSLog(@"dates are the same");
        isTokonValid = NO;
        
    }
    
    return isTokonValid;


}

Monday, July 6, 2015

Android Change Action Bar Colour Programatically

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.primary)));

Tuesday, March 17, 2015

Create Background Thread

 new Thread(new Runnable() {
            @Override
            public void run() {

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                       
                        //Update Ui method

                    }
                });

            }
        });