Tuesday 16 October 2012

Set toolbar for keyboard


- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(keyboardDidShow:) 
                                                 name:UIKeyboardDidShowNotification 
                                               object:nil];
    return YES;
}

- (void)keyboardDidShow:(NSNotification *)note
{
    UIButton *returnBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    returnBtn.frame = CGRectMake(0,-25,320,25);
    returnBtn.adjustsImageWhenHighlighted = NO;
    returnBtn.backgroundColor=[UIColor darkGrayColor];
    returnBtn.titleLabel.textColor=[UIColor whiteColor];
    [returnBtn setBackgroundImage:[UIImage imageNamed:@"keyBtn.png"] forState:UIControlStateNormal];
    
    [returnBtn addTarget:self action:@selector(keyboardBtn:) forControlEvents:UIControlEventTouchUpInside];
    // locate keyboard view
    UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
    UIView* keyboard;
    for(int i=0; i<[tempWindow.subviews count]; i++) {
        keyboard = [tempWindow.subviews objectAtIndex:i];
        // keyboard found, add the button
        if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES)
            //  if (txtTag==5) {
            [keyboard addSubview:returnBtn];
    }
}

-(IBAction)keyboardBtn:(id)sender
{
    [yourTextField resignFirstResponder];/// resign all textfield
}

Local Notification....


- (void) scheduleAlarm:(NSString *)PaymentTitle FireDate:(NSDate *)tempFireDate {
    
    NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
    
    
    NSDate *pickerDate = tempFireDate; //Set yourDate here
    
    // Break the date up into components
    NSDateComponents *dateComponents = [calendar components:( NSYearCalendarUnit | NSMonthCalendarUnitNSDayCalendarUnit )
  fromDate:pickerDate];
    NSDateComponents *timeComponents = [calendar components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit )
  fromDate:pickerDate];
    // Set up the fire time
    NSDateComponents *dateComps = [[NSDateComponents alloc] init];
    [dateComps setDay:[dateComponents day]];
    [dateComps setMonth:[dateComponents month]];
    [dateComps setYear:[dateComponents year]];
    [dateComps setHour:[timeComponents hour]];
// Notification will fire in one minute
    [dateComps setMinute:[timeComponents minute]];
[dateComps setSecond:[timeComponents second]];
    NSDate *itemDate = [calendar dateFromComponents:dateComps];
    [dateComps release];
    
    UILocalNotification *localNotif = [[UILocalNotification alloc] init];
    if (localNotif == nil)
        return;
    localNotif.fireDate = itemDate;
    localNotif.timeZone = [NSTimeZone defaultTimeZone];
    
// Notification details
    localNotif.alertBody = [NSString stringWithFormat:@"Get %@ Payment of %@ Project",PaymentTitle,strProjectName];
// Set the action button
    localNotif.alertAction = @"View";
    
    localNotif.soundName = UILocalNotificationDefaultSoundName;
    localNotif.applicationIconBadgeNumber = 1;
    
// Specify custom data for the notification
    NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"iClientManagement" forKey:@"App"];
    localNotif.userInfo = infoDict;
    
// Schedule the notification
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
    [localNotif release];
}

Tuesday 9 October 2012

Sort the NSMutableArray with date with string type


 NSMutableArray *tempDateArray = [[NSMutableArray alloc]init];
        for (int i = 0; i < [arrProjectList count]; i++) {
            NSString *strThisDate = [[arrProjectList objectAtIndex:i]valueForKey:@"Last_Date"];
            NSLog(@"\n\n Date here %@",strThisDate);
            [strThisDate retain];
            
            NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
            [dateFormatter setDateFormat:@"EEE, dd-LLL-yyyy"];
            
            NSDate *date = [dateFormatter dateFromString: strThisDate];
            //        date = [self convertStringToDate:strThisDate];
            strThisDate = [date stringFromDateWithFormat:@"yyyy-MM-dd 00:00:00 +0000"];
            [tempDateArray addObject:strThisDate];
        }
        [tempDateArray retain];
        NSArray *arrDates = [[NSArray alloc]initWithArray:tempDateArray];
        [arrDates retain];
        [tempDateArray sortUsingSelector:@selector(compare:)];

        NSMutableArray *temparrProjectList = [[NSMutableArray alloc]init];
        for (int j = 0; j < [tempDateArray count]; j++) {
            NSString *tempstrThisDate = [tempDateArray objectAtIndex:j];
            for (int i = 0; i < [arrProjectList count]; i++) {
                NSString *strThisDate = [[arrProjectList objectAtIndex:i]valueForKey:@"Last_Date"];
                NSLog(@"\n\n Date here %@",strThisDate);
                [strThisDate retain];
                
                NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
                [dateFormatter setDateFormat:@"EEE, dd-LLL-yyyy"];
                
                NSDate *date = [dateFormatter dateFromString: strThisDate];
                //        date = [self convertStringToDate:strThisDate];
                strThisDate = [date stringFromDateWithFormat:@"yyyy-MM-dd 00:00:00 +0000"];
                if ([strThisDate isEqualToString:tempstrThisDate]) {
                    if (![temparrProjectList containsObject:[arrProjectList objectAtIndex:i]]) {
                        [temparrProjectList addObject:[arrProjectList objectAtIndex:i]];    
                    }
                }
                
            }
        }
        [temparrProjectList retain];
        arrProjectList = temparrProjectList;

Local Notification in iPhone SDK.


Change some code and get your output...
here i give the logic for set notification before 1 day of selected day.

-(IBAction)btnGo_Clicked:(id)sender{

    NSLog(@"\n ----------->>Go Clicked");
    Class cls = NSClassFromString(@"UILocalNotification");
    if (cls != nil) {
        NSString *kRemindMeNotificationDataKey = @"kRemindMeNotificationDataKey";

        ///bellow i set 1 day before give us notification
        NSDateComponents *dc = [[NSCalendar currentCalendar] components:NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit|NSQuarterCalendarUnit fromDate:[exdatePicker date]];
        [dc setDay:dc.day - 1];
        NSDate *noticeDate = [[NSCalendar currentCalendar] dateFromComponents:dc];

        
        NSDateFormatter* dateFormatterstring = [[NSDateFormatter alloc] init];
        [dateFormatterstring setDateFormat:@"dd-MM-yyyy hh:mm:ss a"];
        NSString *dateString = [dateFormatterstring stringFromDate:noticeDate];

        txtExpirayDate.text = dateString;
        UILocalNotification *notification = [[cls alloc] init];

        notification.fireDate = noticeDate;
        notification.timeZone = [NSTimeZone defaultTimeZone];
        notification.alertBody = [NSString stringWithFormat:@"%@ your Licence Expiry Date is Tommorow",txtLicence.text];
        notification.alertAction = @"Show me";
        notification.soundName = UILocalNotificationDefaultSoundName;
        notification.applicationIconBadgeNumber = 1;
        NSDictionary *userDict = [NSDictionary dictionaryWithObject:txtLicence.text forKey:kRemindMeNotificationDataKey];
        notification.userInfo = userDict;
        [[UIApplication sharedApplication] scheduleLocalNotification:notification];
        [notification release];
    }
    exdatePicker.hidden=YES;
}