2012-04-13 143 views
1

我正尝试将照片上传到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 +,以及其他一切容易吗?

+1

大家好, 以为我会与大家在这里分享,我刚刚发布的教程在我的关于如何上传照片博客并使用最新的Facebook SDK发布状态更新。还有一个示例项目需要下载。 看看这里: http://xcodenoobies.blogspot.com/2012/09/how-to-upload-photo-and-update-status.html 谢谢。 – GeneCode 2012-09-07 12:20:10

回答

2

而不是使用图形你为什么不尝试:

 if ([fbAppDelegate.facebook isSessionValid]) { 
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:                  @"http://hd.ipad-wallpapers.fr/thumbs/wooden_apple_logo_4-t1.jpg // but could also use UIImage", @"picture", nil]; // you don't 



    [fbAppDelegate.facebook dialog:@"feed" andParams:params andDelegate:self]; 

} 

// this is what I do ..... 
+0

嗨,谢谢。但仍然崩溃。你能分享我的所有代码吗? – Edig 2012-04-13 18:48:58

+0

什么是崩溃日志? – MCKapur 2012-04-14 01:56:02

+0

我fixit。我添加了一个静态库,我使用Facebook提供的脚本构建。但是我的项目是ARC,我遇到了麻烦。我得到Facebook的来源和重构到ARC修改我需要的一切,我再次将其添加到我的项目,它的工作原理:)谢谢 – Edig 2012-04-14 03:23:15

相关问题