Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Button 1
- - (IBAction)btnFavCol:(id)sender {
- [self chkResponse];
- }
- -(void)chkResponse
- {
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- NSString *email = [defaults objectForKey:@"email"];
- NSString *passWord = [defaults objectForKey:@"passWord"];
- NSLog(@"user name is = %@ and password is = %@",email,passWord);
- NSString *parameterisedUrl = [NSString stringWithFormat:@"http://www.coloragon.com/ajax_svc.php?controller=fetchFavouratePalletColors&email=%@&password=%@",email,passWord];
- NSURL *url = [NSURL URLWithString:parameterisedUrl];
- NSURLRequest *request = [NSURLRequest requestWithURL:url];
- [NSURLConnection connectionWithRequest:request delegate:self];
- NSURLResponse *response;
- NSError *error;
- NSData * data = [NSURLConnection sendSynchronousRequest:request
- returningResponse:&response
- error:&error];
- if (!error) {
- NSString *str=[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
- NSLog(@"Login response: is %@",str);
- }
- else{
- NSString *str=[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
- NSLog(@"Login response: is %@",str); //getting response
- NSLog(@"I am here in else");
- }
- }
- - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
- NSLog(@"ReceivedResponse");
- }
- - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
- // [self.responseDATA appendData:data];
- colorNamesArray = [[NSMutableArray alloc] init];
- colorHexArray = [[NSMutableArray alloc] init];
- paletteIDArray = [[NSMutableArray alloc] init];
- NSDictionary *jsonData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
- NSLog(@"json data is %@",jsonData);
- NSLog(@"object class == %@",[jsonData class]);
- favColorsArray =[jsonData valueForKey:@"r"];
- for(NSArray *tmpArr1 in favColorsArray){
- if([tmpArr1 valueForKey:@"name"]){
- colorName=[tmpArr1 valueForKeyPath:@"name"];
- NSString *colorHex=[tmpArr1 valueForKeyPath:@"colors"];
- NSString *paletteId = [tmpArr1 valueForKey:@"id"];
- [paletteIDArray addObject:paletteId];
- [colorNamesArray addObject:colorName];
- [colorHexArray addObject:colorHex];
- }
- }
- NSLog(@"color names array is %@",colorNamesArray);
- NSLog(@"color hex array is %@",colorHexArray);
- NSUserDefaults *defaultFavColors = [NSUserDefaults standardUserDefaults];
- [defaultFavColors setObject:colorNamesArray forKey:@"colorNamesArray"];
- [defaultFavColors setObject:colorHexArray forKey:@"colorHexArray"];
- [defaultFavColors setObject:paletteIDArray forKey:@"paletteIDArray"];
- [defaultFavColors synchronize];
- FavColorsViewController *favColVC = [[FavColorsViewController alloc] init];
- [self.navigationController pushViewController:favColVC animated:YES];
- }
- - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
- NSLog(@"didFailWithError");
- NSLog( [NSString stringWithFormat:@"Connection failed: %@", error],
- [error description]);
- }
- - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
- NSLog(@"connectionFinishLoading");
- }
- Button 2
- - (IBAction)btnFavGallery:(id)sender {
- [self getGalleries];
- }
- -(void)getGalleries
- {
- NSString *parameterisedUrl = [NSString stringWithFormat:@"http://www.coloragon.com/ajax_svc.php?controller=fetchGalleries&email=saad.khalid@digitalnet.com&password=12345"];
- NSURL *url = [NSURL URLWithString:parameterisedUrl];
- NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
- [theRequest setHTTPMethod:@"POST"];
- [theRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
- NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
- if(theConnection)
- {
- // NSLog(@"Connection Successful");
- NSURLResponse *response;
- NSError *err;
- NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&err];
- NSDictionary *jsonData = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:nil];
- NSMutableArray *galleryNameArray = [[NSMutableArray alloc]init];
- NSMutableArray *galleryIDArray = [[NSMutableArray alloc]init];
- NSLog(@"json data is %@",jsonData);
- NSLog(@"object class == %@",[jsonData class]);
- NSMutableArray *galleriesArray =[jsonData valueForKey:@"gals"];
- for(NSArray *tmpArr1 in galleriesArray){
- if([tmpArr1 valueForKey:@"name"]){
- NSString *galleryName = [tmpArr1 valueForKeyPath:@"name"];
- NSString *galID = [tmpArr1 valueForKey:@"id"];
- [galleryNameArray addObject:galleryName];
- [galleryIDArray addObject:galID];
- }
- }
- NSLog(@"gallery names are %@",galleryNameArray);
- FavGalleriesViewController *favGalVC = [[FavGalleriesViewController alloc] init];
- favGalVC.galleryIDArray = galleryIDArray;
- favGalVC.galleryNameArray = galleryNameArray;
- [self.navigationController pushViewController:favGalVC animated:YES];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement