2015-07-01 157 views
0

我使用iOS上的Facebook SDK(objective-c)在Facebook上共享圖像。下面是我使用的代碼:與facebook共享內容sdk 4.0 + iOS

-(IBAction)facebookShare:(UIButton *)sender { 
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init]; 
photo.image = self.image; 
photo.userGenerated = YES; 
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init]; 
content.photos = @[photo]; 
[FBSDKShareDialog showFromViewController:self withContent:content delegate:self]; 
} 

如果圖像是由我從用戶的畫廊拿起它設置一個UIImage的。當我嘗試按我的按鈕(這個IBAction爲)應用程序崩潰給這個錯誤:

7月1日十點50分23秒。當地PKD [917]:對於PID 922 7月1日10:50錯誤檢索的權利: 23 - [MainViewController sharer:didFailWithError:]:無法識別的選擇器發送到實例0x7fd70940efd0 Jul 1 10:50:23:***終止應用程序由於未捕獲的異常'NSInvalidArgumentException',原因:' - [MainViewController sharer:didFailWithError:]:無法識別的選擇發送到實例0x7fd70940efd0'

這裏是新的錯誤以這種方式固定碼後

FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init]; 
     photo.image = //YOUR IMAGE                 photo.userGenerated = YES; 
     FBSDKSharePhotoContent * photoContent = [[FBSDKSharePhotoContent alloc] init]; 
     photoContent.photos = @[photo]; 
     FBSDKShareDialog *shareDialog = [[FBSDKShareDialog alloc] init]; 
     shareDialog.shareContent = photoContent; 
     shareDialog.delegate = (id)self; 
     shareDialog.fromViewController = self; 
     NSError * error = nil; 
     BOOL validation = [shareDialog validateWithError:&error]; 
     if (validation) { 
      [shareDialog show]; 
     } 

UL 1 15時55分02秒。當地Dailypic [1169]:libMobileGestalt MobileGestalt.c:1025:無法檢索區域信息 7月1日15時55分06秒com.apple.CoreSimulator.SimDevice.D482DFDD -3051-4759-B70D-94EC93BFF5D0.launchd_sim [471](com.apple.imfoundation.IMRemoteURLConnectionAgent):_DirtyJetsamMemoryLimit鍵在此平臺上不可用。 Jul 1 15:55:07 o.local pkd [498]:檢索pid的權利時出錯1169 Jul 1 15:55:07 local Dailypic [1169]:Error Domain = com.facebook.sdk.share Code = 2「 (com.facebook.sdk.share error 2.)「UserInfo = 0x7ffc8a59bcd0 {com.facebook.sdk:FBSDKErrorArgumentValueKey =,com.facebook.sdk:FBSDKErrorDeveloperMessageKey = Feed共享對話框支持FBSDKShareLinkContent。,com .facebook.sdk:FBSDKErrorArgumentNameKey = shareContent} 07月01日15點55分10秒本地securityd [499]:SecTaskCopyAccessGroups而在模擬器中運行,回落到默認未指定鑰匙串訪問組設置

使用不同的仿真器終於解決。

+0

委託方法'分享者:didFailWithError:'的FBSDKShareDialog'未實現'。 – Larme

回答

5

在早期版本的FB SDK中存在一個錯誤,但在這裏似乎缺少必需的委託方法實現。

 FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init]; 
     photo.image = //YOUR IMAGE                 photo.userGenerated = YES; 
     FBSDKSharePhotoContent * photoContent = [[FBSDKSharePhotoContent alloc] init]; 
     photoContent.photos = @[photo]; 
     FBSDKShareDialog *shareDialog = [[FBSDKShareDialog alloc] init]; 
     shareDialog.shareContent = photoContent; 
     shareDialog.delegate = (id)self; 
     shareDialog.fromViewController = self; 
     NSError * error = nil; 
     BOOL validation = [shareDialog validateWithError:&error]; 
     if (validation) { 
      [shareDialog show]; 
     } 

並實施所需的代表方法

- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results { 
    // handle 
} 
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error{ 
    // handle 
} 
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer{ 
    // handle 
} 
+0

內容結果作爲未聲明的標識符,並用於:路徑是正確的添加_image? – Spidersaw

+0

編輯答案 – Andrea

+0

好的,現在代碼似乎很好,但是當我嘗試運行它時,我無法得到我的對話框,如果我「強制」[shareDialog show];該應用程序崩潰 – Spidersaw