Tuesday, 16 October 2012

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;
}

Tuesday, 28 August 2012

For remove UIDevice orientation warning just put bellow code in your file where you want to put fix orientation


For example if you want to your project only support Landscape or Portrait Orientation then when you put bellow line... i.e

-(void)viewWillAppear:(BOOL)animated
{
    [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
}

then its give warning like...
'UIDevice' may not respond to 'setOrientation:'

so for solve this warning just put bellow code where you use this line


@interface UIDevice (MyPrivateNameThatAppleWouldNeverUseGoesHere)
- (void) setOrientation:(UIInterfaceOrientation)orientation;
@end

Monday, 27 August 2012

Get Address From Latitude,Longitude....

Hi Friends,
Very simple method for get address from latitude and longitude method is bellow..


-(NSString *)getAddressFromLatLon:(double)pdblLatitude withLongitude:(double)pdblLongitude
{
    NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%f,%f&output=csv",pdblLatitude, pdblLongitude];
    NSError* error;
    NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString] encoding:NSASCIIStringEncoding error:&error];
    locationString = [locationString stringByReplacingOccurrencesOfString:@"\"" withString:@""];
    return [locationString substringFromIndex:6];
}

and for get output just call this method like bellow..

NSString *strAddress = [self getAddressFromLatLon:yourLatitude withLongitude:yourLongitude];

NSLog(@"Address is %@",strAddress);



Friday, 24 August 2012

Rotate,Scale(ZoomIn,Zoomout) Multiple Image with GestureRecognizer...Very Easy..

       
        If we want to add Images Dynamically or custom more then time on the view ny the user and after that if we want to modify that image or recognize by Rotation or zoomin,zoomout then bellow code is very important and easy to use...

here, first you define the delegate and 2 variable in yourViewController.h file like bellow


@interface ViewController : UIViewController<UIGestureRecognizerDelegate>{

          CGFloat lastScale;
          CGFloat lastRotation;
}

after that in yourViewController.m file


-(void)yourMethodForAddImage{
        UIImageView *img = [[UIImageView alloc]init];
        [arrTag addObject:img];
        [arrTag retain];
        img.tag = [arrTag count];
        img.image = [UIImage imageNamed:[yourArray objectAtIndex:index]];//here use your array of object or array of imagename
        img.userInteractionEnabled = YES;
        img.frame = CGRectMake(yourViewController.view.center.x,yourViewController.view.center.y, 200, 200);
        
        UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scale:)];
        [pinchRecognizer setDelegate:self];
        [img addGestureRecognizer:pinchRecognizer];
        [pinchRecognizer release];
       
        UIRotationGestureRecognizer *rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];
        [rotationRecognizer setDelegate:self];
        [img addGestureRecognizer:rotationRecognizer];
        [rotationRecognizer release];

        UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];
        [tapRecognizer setNumberOfTapsRequired:1];
        [tapRecognizer setDelegate:self];
        [img addGestureRecognizer:tapRecognizer];
        [tapRecognizer release];
        
       
        [yourViewController.view addSubview:img];
        [yourViewController.view bringSubviewToFront:img];
        [img release];
}

After that define bellow Methods..


#pragma mark GestureRecognizer Methods

-(void)scale:(id)sender {
     UIView *imgTempGest = [sender view];
    
     if([(UIPinchGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {
             lastScale = 1.0;
      return;
     }
     CGFloat scale = 1.0 - (lastScale - [(UIPinchGestureRecognizer*)sender scale]);
     CGAffineTransform currentTransform = [(UIPinchGestureRecognizer*)sender view].transform;
     CGAffineTransform newTransform = CGAffineTransformScale(currentTransform, scale, scale);
     [[(UIPinchGestureRecognizer*)sender view] setTransform:newTransform];
    [imgTempGest setTransform:newTransform];
    
     lastScale = [(UIPinchGestureRecognizer*)sender scale];
}

-(void)rotate:(id)sender {
    
    UIView *imgTempGest = [sender view];
    
     if([(UIRotationGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {
             lastRotation = 0.0;
             return;
      }
      CGFloat rotation = 0.0 - (lastRotation - [(UIRotationGestureRecognizer*)sender rotation]);
      CGAffineTransform currentTransform = [(UIPinchGestureRecognizer*)sender view].transform;
      CGAffineTransform newTransform = CGAffineTransformRotate(currentTransform,rotation);
      [[(UIRotationGestureRecognizer*)sender view] setTransform:newTransform];
      [imgTempGest setTransform:newTransform];
      lastRotation = [(UIRotationGestureRecognizer*)sender rotation];
}

-(void)tapped:(id)sender {
      UIView *imgTempGest = [sender view];
      [[[(UITapGestureRecognizer*)sender view] layer] removeAllAnimations];
      [[imgTempGest layer] removeAllAnimations];
}


Thursday, 23 August 2012

Move Object on view with Filtered Class Like.. UIImageView class and its tag,etc.


Here you can easily move image object with particular tag or only for imageview class.

if you want to some selected images are only  move then just give here image.tag = something and then bellow method in put condition like 

if(tempImage.tag == yourTag)
{
     tempImage.center = pointToMove; 
}

you can easily handle your all object..

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{
    
       UITouch *tap = [touches anyObject];

       CGPoint pointToMove = [tap locationInView:viewBoard];
       if([touch.view isKindOfClass:[UIImageView class]])
      {

             UIImageView *tempImage=(UIImageView *) tap.view;
             [UIView beginAnimations:nil context:NULL];
             [UIView setAnimationDuration:0.0f];
             [UIView setAnimationBeginsFromCurrentState:YES];
             [UIView setAnimationCurve:UIViewAnimationCurveLinear];
             tempImage.center = pointToMove; 
             [UIView commitAnimations];    
         }
}