Tuesday, 20 March 2012

Adding "To Field" in ShareKit Email(Pre Setup)

In the button press.


NSString *someText = @"This is a blurb of text I highlighted from a document.";
SHKItem *item = [SHKItem text:someText];

[item setCustomValue:@"your@recipient.com" forKey:@"toField"];
// Share the item [SHKMail shareItem:item];



The add these lines in SHKMail.m in the method sendMail:
[mailController setSubject:item.title];
[mailController setMessageBody:body isHTML:YES];

// **start of added code
NSString *recipient = [item customValueForKey:@"toField"];
NSLog(@"recipient: %@", recipient);
if (recipient != nil) {
    NSArray *recipients = [[NSArray alloc] initWithObjects:recipient, nil];
    [mailController setToRecipients:recipients];
    [recipient release];
    [recipients release];
}
// **end of added code

[[SHK currentHelper] showViewController:mailController];


Email /Facebook /twitter only By Share-kit with a button press.

First import   #import "SHKMail.h" in the view Controller.


-(IBAction)Emailbutton:(id)sender{
    
    SHKItem *item;
     [SHK setRootViewController:self];
    NSURL *url = [NSURL URLWithString:@"sadiq"];
   item = [SHKItem URL:url title:@"Contact"];

    [SHKMail shareItem:item];

}

-(IBAction)FbButton:(id)sender{
 SHKItem *item;
     [SHK setRootViewController:self];
  NSURL *url = [NSURL URLWithString:@"http://www.google.com/"];
item = [SHKItem URL:url title:@"Google"];
[SHKFacebook shareItem:item];

}



Basic MapView Annotation Tuto

Monday, 19 March 2012

Executing a URL within the app.

NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://mma-in-nj.com/iphone/test/register_device.php?dt=%@",token]];
   NSLog(@"URL -- %@",url);
   
    NSMutableURLRequest *request1 = [[[NSMutableURLRequest alloc] init] autorelease];
    [request1 setURL:url];
    [request1 setHTTPMethod:@"GET"];
 
    [request1 setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    
   
    [NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
   
    NSError *error;
    NSURLResponse *response;
    NSData *urlData=[NSURLConnection sendSynchronousRequest:request1 returningResponse:&response error:&error];
   
    NSString *data1=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
    NSLog(@"here...%@",data1);  

Wednesday, 14 March 2012

Setting BackGround image and clearing the view

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    // Add the navigation controller's view to the window and display.
   
    UIView *backgroundView = [[UIView alloc] initWithFrame: _window.frame];
    backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Bg.png"]];
    [_window addSubview:backgroundView];
   
    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];
    return YES;
}

//wherever needed..


- (void)viewDidLoad
{
    [super viewDidLoad];
 
    self.view.backgroundColor=[UIColor clearColor];

}

Saturday, 10 March 2012

Deleting Tableview cell content and updating the content array stored by NSDocumentDirectory

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
       
        [amountSpend removeObjectAtIndex:indexPath.row];
       
        NSLog(@"after Delete-- %@",amountSpend);
       
       
        NSArray *path1 = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory1 = [path1 objectAtIndex:indexPath.row];
       
        NSString *fullFileName1 = [NSString stringWithFormat:@"%@amountSpend", documentsDirectory1];
        [amountSpend writeToFile:fullFileName1 atomically:NO];

       
       
        [tableView reloadData];
        // Delete the row from the data source
       // [tableView deleteRowsAtIndexPaths:[amountSpend indexOfObject:indexPath.row] withRowAnimation:UITableViewRowAnimationFade];
    }  
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }  
}

TableView Editing and Deleting code and Delegate

- (void)viewDidLoad
{
    [super viewDidLoad];
self.navigationItem.rightBarButtonItem = self.editButtonItem;
}


- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

if (editingStyle == UITableViewCellEditingStyleDelete) {

 // Delete the row from the data source
       [tableView deleteRowsAtIndexPaths:[amountSpend indexOfObject:indexPath.row] withRowAnimation:UITableViewRowAnimationFade];
    }  
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }  
}

Friday, 2 March 2012

Trimming photo to a specific size with a php script.

NSString *str=[NSString stringWithFormat: @"http://iphone.jiujitsucoach.com/includes/timthumb.php?src=%@&h=150&w=150",[imageArray objectAtIndex:currentIndex_]];
   
    NSURL * imageURL = [NSURL URLWithString:str];
    NSData * imageData = [NSData dataWithContentsOfURL:imageURL];
    UIImage * image = [UIImage imageWithData:imageData];

Retrieving multiple images saved in documents directory

- (void)viewDidLoad
{
   [super viewDidLoad];
   
    NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *fullFileName = [NSString stringWithFormat:@"%@imageArray", documentsDirectory];
    imageArray=[[NSMutableArray alloc]initWithContentsOfFile:fullFileName];
}

//where the image need to dispaly..

NSString *str=[NSString stringWithFormat: @"http://iphone.jiujitsucoach.com/includes/timthumb.php?src=%@&h=150&w=150",[imageArray objectAtIndex:currentIndex_]];
   
    NSURL * imageURL = [NSURL URLWithString:str];
    NSData * imageData = [NSData dataWithContentsOfURL:imageURL];
    UIImage * image = [UIImage imageWithData:imageData];

Adding multiple images in to an array parsed from a server and saving it in the document directory.

- (void)viewDidLoad
{
   [super viewDidLoad];

 NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory,      NSUserDomainMask, YES);
 NSString *documentsDirectory = [paths objectAtIndex:0];
   NSString *fullFileName = [NSString stringWithFormat:@"%@imageArray", documentsDirectory];
   imageArray=[[NSMutableArray alloc]initWithContentsOfFile:fullFileName];

       if([imageArray count]==0){

           imageArray=[[NSMutableArray alloc]init];if(xmlElementObjects !=nil)
       {
           [xmlElementObjects release];
       }
       xmlElementObjects = [[NSMutableArray alloc] init];
     
    
     
     
       NSData *xml = [NSData dataWithContentsOfURL: [NSURL URLWithString:@"http://iphone.jiujitsucoach.com/admin/gallery.php?action=generate"]];
       self.parser=[[NSXMLParser alloc]initWithData:xml];
       [self.parser setDelegate:self];
       [self.parser parse];
       [self.parser release];
       self.parser=nil;
     
           
       for(int i=0;i<[xmlElementObjects count];i++){
         
           eleme = [xmlElementObjects objectAtIndex:i];
                     [imageArray addObject:eleme.imageurl];
         
           [imageArray writeToFile:fullFileName atomically:NO];
      
         
       }
         
        NSLog(@"Not from Cache imageArry-- %@",imageArray);
       }
     
       else{
         
           NSLog(@"Hi from cache..");
           fullFileName = [NSString stringWithFormat:@"%@imageArray", documentsDirectory];
           imageArray=[[NSMutableArray alloc]initWithContentsOfFile:fullFileName];
           NSLog(@"imageArry-- %@",imageArray);

       }
}