OGeek|极客世界-中国程序员成长平台

标题: ios - Facebook 分享 iOS Swift [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 16:38
标题: ios - Facebook 分享 iOS Swift

我正在尝试在我的 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)

info.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



Best Answer-推荐答案


为什么不使用 Social Framework 来实现呢?它很容易实现和显示文本、url、照片。

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

2) 点击 Link Binary with Libraries 并添加 Social framework

3) 在您的 View Controller 中导入

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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) Powered by Discuz! X3.4