Reputation: 949
I have used the below code to share an image on fb wall:
NSData *imageData = UIImageJPEGRepresentation(self.selectedImage, 10);
NSMutableDictionary* variables = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"your caption message", @"message", imageData, @"data", nil];
FbGraphResponse *fb_graph_response = [[sharedSingleton fbGraph] doGraphPost:@"me/photos" withPostVars:variables];
NSLog(@"postMeFeedButtonPressed: %@", fb_graph_response.htmlResponse);
but the app is getting crashed when ever I try to share. Guide me to solve this issue
Upvotes: 0
Views: 457
Reputation: 925
// JSON EXAMPLE
.H FILE
NSMutableArray *arrRespone;
NSMutableDictionary *resultsDictionary;
.M FILE
// how can print array json values into uitableview in iphone
@interface ViewController ()
@end
@implementation ViewController
@synthesize tableView1;
{
arrRespone=[NSMutableArray new];
practice_ArrayForDisplayingEx=[[NSArray alloc]initWithObjects:@"bhupi",@"bhupi",@"bhupi",@"bhupi",nil];
dispatch_async(kBgQueue, ^
{
NSData* dataURL = [NSData dataWithContentsOfURL: kLatestKivaLoansURL]; [self performSelectorOnMainThread:@selector(fetchedData:) withObject:dataURL waitUntilDone:YES]; });
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
(void)fetchedData:(NSData *)responseData {
NSError *error;
resultsDictionary = [NSJSONSerialization JSONObjectWithData:responseData //1 options:kNilOptions error:&error];
NSDictionary *arrDetails=[[resultsDictionary objectForKey:@"menu"] objectAtIndex:0] ; NSDictionary *genr=[[arrDetails valueForKey:@"categories"] objectAtIndex:0];
NSLog(@"array detailsarray ====>%@",arrDetails); NSLog( @"genreee arrray==%@",genr); //NSLog(@"genrvalueeee -----%@",[genr valueForKey:@"genre"]);
NSLog(@"counttttt===%d",[[genr valueForKey:@"genre" ] count]); NSLog(@"genre objectatindex==%@",[genr valueForKey:@"cliptype"]);
for (int i=0;i<[[genr valueForKey:@"genre" ] count];i++) {
NSDictionary *strDetails=[[genr valueForKey:@"genre"] objectAtIndex:i];
NSString *str=[strDetails valueForKey:@"gname"];
NSLog(@"First string details===>%@",str);
[arrRespone addObject:str];
NSLog(@"response ====>%@",arrRespone);
} [tableView1 reloadData]; }
(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
NSLog(@"numberOfSectionsInTableView");
return 1; }
(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 45;
NSLog(@"heightForRowAtIndexPath");
}
// Customize the number of rows in the table view. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSLog(@"numberOfRowsInSection");
return [arrRespone count]; }
}
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"inside tableview"); static NSString *CellIdentifier = @"TableCell";
//TableCell *cell = (TableCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier];
} // cell.textLabel.text=[arrRespone objectAtIndex:indexPath.row];
NSLog(@"cellvalue:%@",cell.textLabel.text); NSLog(@"inside numberofRowsInsection"); // Configure the cell... cell.textLabel.text = [arrRespone objectAtIndex:indexPath.row];
return cell;
}
@end
Upvotes: 0
Reputation: 925
Try This Code.....
-(IBAction)postPictureButtonPressed:(id)sender {
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:2];
//create a UIImage (you could use the picture album or camera too)
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 20, 240, 240)];
[imgView setImage:[UIImage imageNamed:@"app1.jpg"]];
[self.view addSubview:imgView];
[imgView release];
UIImage *tempimag=imgView.image;
//UIImage *picture = [UIImage imageNamed:@"75x75.png"];
//create a FbGraphFile object insance and set the picture we wish to publish on it
FbGraphFile *graph_file = [[FbGraphFile alloc] initWithImage:tempimag];
NSLog(@"img posted");
//finally, set the FbGraphFileobject onto our variables dictionary....
[variables setObject:graph_file forKey:@"file"];
[variables setObject:@"this is a test message: postPictureButtonPressed" forKey:@"message"];
//the fbGraph object is smart enough to recognize the binary image data inside the FbGraphFile
//object and treat that is such.....
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:@"117795728310/photos" withPostVars:variables];
NSLog(@"postPictureButtonPressed: %@", fb_graph_response.htmlResponse);
NSLog(@"Now log into Facebook and look at your profile & photo albums...");
}
Upvotes: 4