Wednesday, January 23, 2013

LocalNotifications in iPhone



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    [NSThread detachNewThreadSelector:@selector(fireLocalNotifications) toTarget:self withObject:nil];
 
}

-(void) fireLocalNotifications
{

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    for (int i = 0; i < 60; i++)
    {

        UILocalNotification *localNotification = [[UILocalNotification alloc] init];

        if (localNotification == nil){

            return;
}

        NSDate *notifyDate = [[NSDate date] dateByAddingTimeInterval:i * 60];

        localNotification.fireDate = notifyDate     
     
        localNotification.timeZone = [NSTimeZone defaultTimeZone];

        localNotification.alertBody = [NSString stringWithFormat:NSLocalizedString(@"This is local notification %i"), i];

        localNotification f.alertAction = NSLocalizedString(@"My Details", nil);

        localNotification.soundName = UILocalNotificationDefaultSoundName;

        localNotification.applicationIconBadgeNumber = 1;

        [[UIApplication sharedApplication] scheduleLocalNotification: localNotification];
       
        [localNotification release];

    }

    [pool release];
}

Wednesday, January 16, 2013

moving Image in UIView using UIPanGesture


- (void)viewDidLoad{

    YOURIMAGEVIEW = [[UIImageView alloc]initWithFrame:CGRectMake(130350100100)];
    YOURIMAGEVIEW.image = [UIImage imageNamed:@"image.png"];
    [self.view addSubview: YOURIMAGEVIEW];
    YOURIMAGEVIEW.userInteractionEnabled = YES;
    [self.view bringSubviewToFront: YOURIMAGEVIEW];
  
    panRecognizer = [[UIPanGestureRecognizer allocinitWithTarget:self action:@selector(handlePanFrom:)];
    [panRecognizer setMinimumNumberOfTouches:1];
    [panRecognizer setMaximumNumberOfTouches:1];
    [panRecognizer setDelegate:self];
    [self. YOURIMAGEVIEW addGestureRecognizer:panRecognizer];    

}


- (void)handlePanFrom:(UIPanGestureRecognizer*)recognizer {
    
    CGPoint translation = [recognizer translationInView:recognizer.view];
    CGPoint velocity = [recognizer velocityInView:recognizer.view];
    
    if (recognizer.state == UIGestureRecognizerStateBegan) {
    } else if (recognizer.state == UIGestureRecognizerStateChanged) {
      
    } else if (recognizer.state == UIGestureRecognizerStateEnded) {
       // <animate to final position>
        [UIView animateWithDuration:2.0 delay:0  options:UIViewAnimationOptionCurveEaseOut   animations:^ { self.YOURIMAGEVIEW.center = CGPointMake(velocity.x, velocity.y);} completion:NULL];

    }
}
}