![](/img/trans.png)
[英]Facebook iOS SDK v 4.1.0 in Swift with Cocoapods: cannot import modules
[英]Facebook iOS SDK 4.1.0 Share Callback
使用此問題標題中提到的FBSDK,我在視圖控制器中顯示了一個簡單的共享對話框:
// Setup the content for the share
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = linkUrl;
content.contentDescription = description;
content.contentTitle = title;
content.imageURL = imageUrl;
// Show the share dialog
[FBSDKShareDialog showFromViewController:controller
withContent:content
delegate:someDelegate];
並實現委托方法...
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
NSLog(@"Sweet, they shared.");
}
到目前為止,只要用戶在其設備上安裝了Facebook應用程序即可。 當用戶沒有安裝Facebook時,就會出現此問題。 如果是這種情況,Safari可以打開Facebook登錄流程的網絡版本(這很好),但是如果您隨后又切換回原始應用程序而不登錄Facebook /執行任何其他任務,則上面顯示的完成委托方法為調用。
有沒有人有解決此問題的經驗? 似乎應該有一種可靠的方法來確定該職位是否確實存在。
注意:上面的代碼是相當偽的。 在實際的實現中,我確實實現了所有的委托回調(didComplete,didCancel和didFail)。
當然,發布后,我偶然發現了答案。 如果實際發生共享,則在didCompleteWithResults方法中返回的結果字典包含postId鍵。 因此邏輯很簡單:
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
NSURL *fbURL = [NSURL URLWithString:@"fb://"];
if (![[UIApplication sharedApplication] canOpenURL:fbURL])
if (results[@"postId"]) {
NSLog(@"Sweet, they shared, and Facebook isn't installed.");
} else {
NSLog(@"The post didn't complete, they probably switched back to the app");
}
} else {
NSLog(@"Sweet, they shared, and Facebook is installed.");
}
}
盡管這種方法有效,但這似乎並不是解決問題的一種非常安全的方法(Facebook將來將密鑰從“ postId”更改為其他名稱,這是怎么回事?不太可能,但我明白了)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.