我正嘗試將照片上傳到Facebook。我閱讀了很多教程和示例,但仍無法實現。很多時候我在這一行中得到一個EXC_BAD_ACCESS
:發佈照片Facebook iOS
[_facebook requestWithGraphPath:@"me/photos"
andParams:photosParams
andHttpMethod:@"POST"
andDelegate:self];
其他時間什麼都沒有出現。我只希望用戶在Facebook上點擊「分享圖片」時才能登錄。這就是爲什麼我沒有把代表放在appDelegate
。下面是我的代碼:
if (_facebook != nil) {
[self fbDidLogin];
}
_publishedImage = img;
_facebook = [[Facebook alloc] initWithAppId:@"235694579858240" andDelegate:self];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"]
&& [defaults objectForKey:@"FBExpirationDateKey"])
{
_facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
_facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
if (![_facebook isSessionValid])
{
NSArray* permissions = [[NSArray alloc] initWithObjects:
@"offline_access", @"publish_stream", @"publish_actions", @"photo_upload", nil];
[_facebook authorize:permissions];
}
UIImage *imgSource = img;
NSString *strMessage = @"This is the photo caption";
NSMutableDictionary* photosParams = [NSMutableDictionary dictionaryWithObjectsAndKeys:
imgSource,@"source",
strMessage,@"message",
nil];
[_facebook requestWithGraphPath:@"me/photos"
andParams:photosParams
andHttpMethod:@"POST"
andDelegate:self];
我的視圖控制器具有這些代表:
<UIImagePickerControllerDelegate, UIActionSheetDelegate, UIGestureRecognizerDelegate, MFMailComposeViewControllerDelegate, FBSessionDelegate, FBDialogDelegate, FBRequestDelegate>
編輯:是否有任何插件分享照片輕鬆了Facebook,G +,以及其他一切容易嗎?
大家好, 以爲我會與大家在這裏分享,我剛剛發佈的教程在我的關於如何上傳照片博客並使用最新的Facebook SDK發佈狀態更新。還有一個示例項目需要下載。 看看這裏: http://xcodenoobies.blogspot.com/2012/09/how-to-upload-photo-and-update-status.html 謝謝。 – GeneCode 2012-09-07 12:20:10