如何在iPhone的iPhone应用程序中发布图像?

编程入门 行业动态 更新时间:2024-10-28 13:27:25
本文介绍了如何在iPhone的iPhone应用程序中发布图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

任何人都可以帮助我在Facebook上使用目标c发布照片为iphone app.i尝试了但是当我检查iphone.its在simulator中正常工作时它终止。以下是我用来在fb中发布的代码。我使用graph api来开发我的应用程序。

could anyone pls help me to post fotos on facebook using objective c for iphone app.i tried it but its getting terminated when i check with iphone.its working properly in simulator.following is my code i used to post in fb.i use graph api for developing my app.

-(void)fbGraphCallback:(id)sender { if ((fbGraph.accessToken == nil) || ([fbGraph.accessToken length] == 0)) { NSLog(@"You pressed the 'cancel' or 'Dont Allow' button, you are NOT logged into Facebook...I require you to be logged in & approve access before you can do anything useful...."); //restart the authentication process..... [fbGraph authenticateUserWithCallbackObject:self andSelector:@selector(fbGraphCallback:) andExtendedPermissions:@"user_photos,user_videos,publish_stream,offline_access,user_checkins,friends_checkins"]; [self.view addSubview:viewshare]; } else { NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:2]; //imgPicture is my image view name NSLog(@"the Data::%@\n",imgPicture.image); FbGraphFile *graph_file = [[FbGraphFile alloc] initWithImage:imgPicture.image]; [variables setObject:graph_file forKey:@"file"]; [variables setObject:[NSString stringWithFormat:@"%@", txtComment.text] forKey:@"message"]; FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:@"me/photos" withPostVars:variables]; NSLog(@"postPictureButtonPressed: %@", fb_graph_response.htmlResponse); NSLog(@"Now log into Facebook and look at your profile & photo albums..."); txtComment.text=@" "; [txtComment setHidden:YES]; [lblcmt setHidden:YES]; UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:nil message:@"Successfully posted...Now log into Facebook & look at your profile" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alertView show]; [alertView release]; } [fbGraph release]; }

推荐答案

首先,我检查一下facebook( facebook对象)有一个有效的会话:

First I check if facebook(the facebook object) has a valid session:

if (![facebook_ isSessionValid]) { permissions_ = [[NSArray arrayWithObjects:@"read_stream", @"publish_stream", @"offline_access",nil] retain]; [facebook_ authorize:permissions_]; }

当我可以保证我已登录Facebook时发布这样的图像:

When I can guaranty that i'm logged into facebook I post the image like this:

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: image, @"picture", message, @"message", nil]; [facebook_ requestWithGraphPath:@"me/photos" andParams:params andHttpMethod:@"POST" andDelegate:self];

最后,我检查这些方法,以确定图片的成功与否:

Finally I check this methods in for being sure if the image post was succesful or not:

-(void)request:(FBRequest *)request didFailWithError:(NSError *)error { //Error } -(void)request:(FBRequest *)request didLoad:(id)result { //Succes }

更多推荐

如何在iPhone的iPhone应用程序中发布图像?

本文发布于:2023-11-14 02:02:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1585925.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   图像   如何在   iPhone

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!