0

以下のコードを使用して、fbwallで画像を共有しました。

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)送信者 {

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 の例

.H ファイル

NSMutableArray *arrRespone;

NSMutableDictionary *resultsDictionary;

.M ファイル

kBgQueue を定義する dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) //1

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

// iphone で配列 json 値を uitableview に出力する方法

「ViewController.h」をインポート

@インターフェイス ViewController ()

@終わり

@実装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 *エラー;

    resultsDictionary = [NSJSONSerialization JSONObjectWithData:responseData //1 オプション:kNilOptions エラー:&error];

    NSDictionary *arrDetails=[[resultsDictionary objectForKey:@"メニュー"] objectAtIndex:0] ; NSDictionary *genr=[[arrDetails valueForKey:@"categories"] objectAtIndex:0];

    NSLog(@"配列の詳細配列 ====>%@",arrDetails); NSLog(@"genreee配列==%@",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");

    1 を返します。}

  • (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 45;

    NSLog(@"heightForRowAtIndexPath");

}

// テーブル ビューの行数をカスタマイズします。- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSLog(@"numberOfRowsInSection");

[arrRespone カウント] を返します。}

  • (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 (セル == nil) {

    cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier];
    

    } // cell.textLabel.text=[arrRespone objectAtIndex:indexPath.row];

    NSLog(@"cellvalue:%@",cell.textLabel.text); NSLog(@"inside numberofRowsInsection"); // セルを構成します... cell.textLabel.text = [arrRespone objectAtIndex:indexPath.row];

    セルを返します。

}

  • (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // 再作成できるすべてのリソースを破棄します。}

@終わり

于 2013-03-08T10:44:35.977 に答える