ios - Facebook 分享 iOS Swift

标签 ios facebook facebook-graph-api

我正在尝试在我的 iOS 应用程序中使用 Facebook 共享 SDK。

我按照 Facebook 开发者网站中的步骤进行操作。但我有一个问题,问题是 Facebook 没有在我的应用发布的帖子上显示应用名称,如下面的屏幕截图所示。

enter image description here

我的日志中有一些错误:

-canOpenURL: failed for URL: "fbapi20150629:/" - error: "This app is not allowed to query for scheme fbapi20150629"

plugin com.apple.share.Facebook.post invalidated

但是照片分享没有任何问题,唯一的问题是分享的帖子上没有应用名称。

但是在共享 ContentLink 时,我在帖子上看到了应用程序名称,它不适用于照片!!

这是我在 iOS 中分享的代码:

let image = UIImage(data:imageData!)
let content: FBSDKSharePhotoContent = FBSDKSharePhotoContent()
let photo: FBSDKSharePhoto = FBSDKSharePhoto()
photo.image = image
photo.userGenerated = true
content.photos = [photo]
FBSDKShareDialog.showFromViewController(self, withContent: content, delegate: nil)

信息.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>fr_FR</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>$(PRODUCT_NAME)</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.3.0</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>1</string>
    <key>LSApplicationCategoryType</key>
    <string></string>
    <key>NSAppTransportSecurity</key>

    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>
    <key>UIAppFonts</key>
    <array>
        <string>master_of_break.otf</string>
    </array>
    <key>UIBackgroundModes</key>
    <array>
        <string>remote-notification</string>
    </array>
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>UIMainStoryboardFile</key>
    <string>Main</string>
    <key>UIRequiredDeviceCapabilities</key>
    <array>
        <string>armv7</string>
    </array>
    <key>UIStatusBarStyle</key>
    <string>UIStatusBarStyleLightContent</string>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>fb100967589******</string>
            </array>
        </dict>
    </array>
    <key>FacebookAppID</key>
    <string>100967589******</string>
    <key>FacebookDisplayName</key>
    <string>Athéna</string>
    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>fbapi</string>
        <string>fb-messenger-api</string>
        <string>fbauth2</string>
        <string>fbshareextension</string>
    </array>
</dict>
</plist>

使用应用名称共享帖子(适用于 Android)

enter image description here

最佳答案

为什么不使用社交框架来实现这个?它非常容易实现并显示文本、网址、照片。

您只需按照以下步骤操作:- 1) 转到您的应用程序 -> 构建阶段

2) 单击“Link Binary with Libraries”并添加社交框架

3) 在 View Controller 中导入 <Social/Social.h>

4)在您的共享操作中写入以下代码:-

if  SLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook)
{
    let fbShare = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
    fbShare.setInitialText("Swift programming")
    fbShare.addURL(NSURL(string: filePath)) 
    fbShare.addImage(UIImage(named:"ImageName")) 

    self.presentViewController(fbShare, animated: true, completion: nil)
}

否则您可以点击以下链接进行集成:-

http://www.theappguruz.com/blog/facebook-integration-using-swift

要显示您的应用程序链接,请参阅以下内容:-

https://developers.facebook.com/docs/applinks/ios

关于ios - Facebook 分享 iOS Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37376556/

相关文章:

ios - 如何使用 MKDirections 请求支持多种传输类型

objective-c - ABMultiValueRef nil 值检查

javascript - 如何获取某个页面的 Facebook 帖子及其评论?

Facebook 图形 API : Getting the total number of posts

facebook - 使用 facebook 登录我的网站

facebook - FB Local Payment error : "Can' t parse open graph object. Property price doesn't exist for item”

ios - 普通非管理员用户通过 iOS 应用程序将照片发布到 facebook 粉丝页面

ios - 自定义动画 : easing out

ios - 突出显示手指下的标签

java - 如何在 Facebook 广告标题中显示 & 符号