0

我已使用以下代码在 fb 墙上分享图像:

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);

但是当我尝试分享时,应用程序就会崩溃。指导我解决这个问题

4

2 回答 2

4

试试这个代码.....

-(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...");

}

于 2012-08-22T06:30:19.870 回答
0

// JSON EXAMPLE

.H FILE

NSMutableArray *arrRespone;

NSMutableDictionary *resultsDictionary;

.M FILE

define kBgQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) //1

define kLatestKivaLoansURL [NSURL URLWithString: @"http://www.indiaglitz.com/json/vod_menu_init.asp"]

// how can print array json values into uitableview in iphone

import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize tableView1;

  • (void)viewDidLoad

{

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]; }

pragma mark Table view methods

  • (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]; }

  • (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

}

  • (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;

}

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

@end

于 2013-03-08T10:44:35.977 回答