Wednesday, April 3, 2013

Get custom cell label text on didSelectRowAtIndexPath IOS....


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
myCustomCell *cell = (myCustomCell*)[tableView cellForRowAtIndexPath:indexPath];

NSLog(@"cell label text...%@",cell.textLabel.text);

}

Tuesday, April 2, 2013

set alarm for selected days in iphone using LocalNotification


If you have the time which you have to fire notification every day, you should do this:----
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSDateComponents *components = [[NSDateComponents alloc] init];
    for (NSMutableArray * alarmDayArr in self.reminderArr) {
        int count=[alarmDayArr count];
        if(!count){
            continue;
        }

        int day =0;
        int month=0;
        int year=0;
        int hour =0;
        int minutes=0;

        for ( int i=0;i<3;i++) {
            NSString * dayTime=[alarmDayArr objectAtIndex:i ];
            if (i==0) {
                day = [dayTime intValue];    
            }else if(i==1){
                month = [dayTime intValue];                    
            }else if(i==2){
                year = [dayTime intValue];    

            }
        }
        for ( int i=3;i<count;i++) {
            NSString * dayTime=[alarmDayArr objectAtIndex:i ];
            hour = [[dayTime substringToIndex:2] intValue];
            minutes = [[dayTime substringFromIndex:3] intValue];

            [components setDay:day];
            [components setMonth:month];
            [components setYear:year];
            [components setMinute:minutes];
            [components setHour:hour];


            NSDate *myNewDate = [calendar dateFromComponents:components];

            [self scheduleNotificationForDate:myNewDate];

        }
    }

    [components release];
    [calendar release];
then from here it will connect to the main notification firing method
[self scheduleNotificationForDate:myNewDate];
-(void) scheduleNotificationForDate: (NSDate*)date {
    /* Here we cancel all previously scheduled notifications */
    [[UIApplication sharedApplication] cancelAllLocalNotifications];
    UILocalNotification *localNotification = [[UILocalNotification alloc] init];
    localNotification.fireDate = date;
    NSLog(@"Notification will be shown on: %@ ",localNotification.fireDate);

    localNotification.timeZone = [NSTimeZone defaultTimeZone];
    localNotification.alertBody = @"Your Notification Text"
    localNotification.alertAction = NSLocalizedString(@"View details", nil);

    /* Here we set notification sound and badge on the app's icon "-1" 
     means that number indicator on the badge will be decreased by one 
     - so there will be no badge on the icon */

    localNotification.repeatInterval = NSDayCalendarUnit;
    localNotification.soundName = UILocalNotificationDefaultSoundName;
    localNotification.applicationIconBadgeNumber = -1;

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}

Monday, March 25, 2013

fast Downloading Images From server and save to document directory

Add New Class of type NSobject :-
.H file :-


#import <Foundation/Foundation.h>

@interface downloadImageClass : NSObject{

}
+ (void)processImageDataWithURLString:(NSString *)urlString andBlock:(void (^)(NSData *imageData))processImage;


@end


.M file :-

#import "downloadImageClass.h"
#import <QuartzCore/QuartzCore.h>

@implementation downloadImageClass

+ (void)processImageDataWithURLString:(NSString *)urlString andBlock:(void (^)(NSData *imageData))processImage
{
    NSURL *url = [NSURL URLWithString:urlString];
    
    dispatch_queue_t callerQueue = dispatch_get_current_queue();
    dispatch_queue_t downloadQueue = dispatch_queue_create("com.myapp.processsmagequeue", NULL);
    dispatch_async(downloadQueue, ^{
        NSData * imageData = [NSData dataWithContentsOfURL:url];
        
        dispatch_async(callerQueue, ^{
            processImage(imageData);
        });
    });
    dispatch_release(downloadQueue);
}




@end



Save Images to document Directory  :-


- (void)save_to_document_directory{

    NSArray *pathArr = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [pathArr objectAtIndex:0];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *dirPath1 = [path stringByAppendingPathComponent:@"FolderNserverame"];
    self.dirPath = dirPath1;
if (![fileManager fileExistsAtPath:dirPath1]) {
[fileManager createDirectoryAtPath:dirPath1 withIntermediateDirectories:NO attributes:nil error:nil];
}
NSError *error;
for (NSString *file in [fileManager contentsOfDirectoryAtPath:dirPath1 error:&error]) {
BOOL success = [fileManager removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirPath1, file] error:&error];
if (!success || error) {
// it failed.
}
}
    
    for (int i = 0 ; i < [myimagesArray count]; i++) {
        [WebImageOperations processImageDataWithURLString:[myimagesArray objectAtIndex:i] andBlock:^(NSData *imageData) {
          
            
                NSString *imageName = [[[self.responseDataDic objectAtIndex:i]objectForKey:@"Name"]stringByAppendingString:@".png"];
                NSLog(@"imageName....%@",imageName);
                if (![fileManager fileExistsAtPath:[dirPath1 stringByAppendingPathComponent:imageName]]) {
                    [fileManager createFileAtPath:[dirPath1 stringByAppendingPathComponent:imageName] contents:imageData attributes:nil];
                }
           

            
        }];
    }
    
}

Sunday, March 24, 2013

Facebook login dialog with UIAlertView


Because at the clickedButtonAtIndex function the view isn't closed and this can cause problems.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

}

So write FBLogin Method in:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{

[Self showFBLoginDialog];

}

Monday, March 18, 2013

UIRefreshControl in iOS


UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
    [refreshControl addTarget:self action:@selector(DoRefresh:) forControlEvents:UIControlEventValueChanged];
    [self.myTableView addSubview:refreshControl];

Wednesday, March 13, 2013

Save Image to document directory with timestamp ..ios


NSTimeInterval timeStamp = [[NSDate date] timeIntervalSince1970];
     NSNumber *timeStampObj = [NSNumber numberWithDouble: timeStamp];
    
    NSString  *imagePath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/capturedImage%@.jpg",timeStampObj]];

Taking High resolution screenshot for ratina display ... iOS


CGRect screenRect = CGRectMake(0.0f, 44.0f,320.0f, 424.0f);


//High Resolution ScreenShot (640*848)
 UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque,  [[UIScreen mainScreen] scale]);
     [view.layer renderInContext:UIGraphicsGetCurrentContext()];
     
     UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
     
     UIGraphicsEndImageContext();


//Low Resolution ScreenShot (320*424)


UIGraphicsBeginImageContext(screenRect.size);

CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor blackColor] set];
CGContextFillRect(ctx, screenRect);
    [self.view.layer renderInContext:ctx];
screenImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();