[英]Sharing content with facebook sdk 4.0 + iOS
我在iOS(objective-c)上使用Facebook SDK來在Facebook上共享圖像。 這是我使用的代碼:
-(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];
}
其中image是我通過從用戶的庫中選擇它設置的UIImage。 當我嘗試按下按鈕(使用此IBAction)時,應用程序崩潰,並出現以下錯誤:
7月1日10:50:23 .local pkd [917]:錯誤獲取pid 922的權利7月1日10:50:23-[MainViewController sharer:didFailWithError:]:無法識別的選擇器發送到實例0x7fd70940efd0 7月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 .local 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密鑰在此平台上不可用。 7月1日15:55:07 o.local pkd [498]:錯誤獲取pid 1169的權利7月1日15:55:07 local Dailypic [1169]:錯誤Domain = com.facebook.sdk.share代碼= 2“操作無法完成。(com.facebook.sdk.share錯誤2。)“ UserInfo = 0x7ffc8a59bcd0 {com.facebook.sdk:FBSDKErrorArgumentValueKey =,com.facebook.sdk:FBSDKErrorDeveloperMessageKey = Feed共享對話框支持FBSDKShareLinkContent。,com.facebook .sdk:FBSDKErrorArgumentNameKey = shareContent} 7月1日15:55:10本地安全性[499]:SecTaskCopyAccessGroups在模擬器中運行時未指定鑰匙串訪問組,並恢復為默認設置
最后使用其他仿真器解決了。
早期版本的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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.