LOGIN(JSON)

.H

#import <UIKit/UIKit.h>
@class Twitter_SearchViewController;
@interface LoginViewController : UIViewController
{
NSMutableData *responseData;
NSMutableArray *tweets;
}
@property (nonatomic, retain) IBOutlet Twitter_SearchViewController *viewController;
@property (nonatomic, retain) NSMutableArray *tweets;
-(IBAction)actionLogin;
@end

.M

 

#import “LoginViewController.h”
#import “JSON.h”
#import “Twitter_SearchViewController.h”
@interface LoginViewController ()

@end

@implementation LoginViewController
@synthesize viewController,tweets;
– (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

– (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
-(IBAction)actionLogin
{
responseData = [[NSMutableData data] retain];
tweets = [NSMutableArray array];
NSURLRequest *request = [NSURLRequest requestWithURL:
[NSURL URLWithString:@”http://vimeo.com/api/v2/video/38356.json”%5D%5D;
[[NSURLConnection alloc] initWithRequest:request delegate:self];

}

#pragma mark NSURLConnection delegate methods
– (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[responseData setLength:0];
}

– (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
}

– (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
}

– (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];

NSMutableArray *allTweets = [responseString JSONValue];

//NSArray *allTweets = [results objectForKey:@”results”];
viewController=[[Twitter_SearchViewController alloc]init];

UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:viewController];

[viewController setTweets:allTweets];

[self presentViewController:nav animated:YES completion:nil];

}

– (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

 

ImageView with TapGestor

//VIEWDIDLOAD

imageview1.userInteractionEnabled = YES;

UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(myFunction:)];

tapped.numberOfTapsRequired = 1;

[imageview1 addGestureRecognizer:tapped];

/////

-(void)myFunction :(id) sender

{

UITapGestureRecognizer *gesture = (UITapGestureRecognizer *) sender;

NSLog(@”Tag = %d”, gesture.view.tag);

}

SAVE IMAGE N DOCUMENTDIRECTORY NUMBER WISE

LIKE:-

J1.png

J2.png

/////////////

 

.h

int nImageCount;

.m

– (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

nImageCount = nImageCount +1;

UIImage *pickedImage = [info objectForKey:UIImagePickerControllerEditedImage];

NSData *data=UIImagePNGRepresentation(pickedImage);

NSString *FileName=[NSString stringWithFormat:@”J%d.png”, nImageCount];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *tempPath = [documentsDirectory stringByAppendingPathComponent:FileName];

[data writeToFile:tempPath atomically:YES];

[picker dismissViewControllerAnimated:YES completion:nil];

 

 

}

 

Save the vedio in DocumentDirectory(Date&Time Wise)

//http://stackoverflow.com/questions/15518925/how-to-save-video-in-documents-folder-then-upload-to-server

 

– (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

////////////////////////////////////////////////////////////

[self dismissViewControllerAnimated:NO completion:nil];

NSString *type = [info objectForKey:UIImagePickerControllerMediaType];

if ([type isEqualToString:(NSString *)kUTTypeVideo] || [type isEqualToString:(NSString *)kUTTypeMovie])

{

NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];

videoURL = [info objectForKey:UIImagePickerControllerMediaURL];

NSLog(@”found a video”);

// Code To give Name to video and store to DocumentDirectory //

NSData *videoData = [NSData dataWithContentsOfURL:videoURL];

videoData = [NSData dataWithContentsOfURL:videoURL];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init] ;

[dateFormat setDateFormat:@”dd-MM-yyyy||HH:mm:SS”];

NSDate *now = [[NSDate alloc] init];

NSString *theDate;

theDate = [dateFormat stringFromDate:now];

NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@”Default Album”];

if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])

[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:nil];

NSString *videopath= [[NSString alloc] initWithString:[NSString stringWithFormat:@”%@/%@.mov”,documentsDirectory,theDate]];

BOOL success = [videoData writeToFile:videopath atomically:NO];

NSLog(@”Successs:::: %@”, success ? @”YES” : @”NO”);

NSLog(@”video path –> %@”,videopath);

}

[picker dismissViewControllerAnimated:YES completion:nil];

}