Facebookに写真をアップロードしようとしています。多くのチュートリアルと例を読みましたが、まだ機能しません。何度もEXC_BAD_ACCESS
この行に表示されます:
[_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];
私の ViewController には次のデリゲートがあります。
<UIImagePickerControllerDelegate, UIActionSheetDelegate, UIGestureRecognizerDelegate, MFMailComposeViewControllerDelegate, FBSessionDelegate, FBDialogDelegate, FBRequestDelegate>
編集: Facebook や G+ などで簡単に写真を共有できるプラグインはありますか?