我正在获得Use of undeclared identifier
使用的每个Facebook对象
遵循本教程:教程:如何在SWIFT中共享FACEBOOK SDK 4.1.X
但是我遇到了以下错误:
我通过cocoapods添加了Facebook框架:
pod 'FBSDKCoreKit'
pod 'FBSDKShareKit'
并成功安装
我添加了桥接头
#ifndef Bridging_Header_h
#define Bridging_Header_h
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKShareKit/FBSDKShareKit.h>
#endif /* Bridging_Header_h */
桥接头已连接:
我已经配置了.plist
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb*****</string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string>*****</string>
<key>FacebookDisplayName</key>
<string>*****</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>facebook.com</key>
<dict>
<key>NSIncludesSubdomains</key> <true/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/>
</dict>
<key>fbcdn.net</key>
<dict>
<key>NSIncludesSubdomains</key> <true/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/>
</dict>
<key>akamaihd.net</key>
<dict>
<key>NSIncludesSubdomains</key> <true/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/>
</dict>
</dict>
</dict>
这是代码:
let content : FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string: "<INSERT STRING HERE>")
content.contentTitle = "<INSERT STRING HERE>"
content.contentDescription = "<INSERT STRING HERE>"
content.imageURL = NSURL(string: "<INSERT STRING HERE>")
let button : FBSDKShareButton = FBSDKShareButton()
button.shareContent = content
button.frame = CGRectMake((UIScreen.mainScreen().bounds.width - 100) * 0.5, 50, 100, 25)
self.view.addSubview(button)
如果您使用Pods,并且您的项目在Swift上,则无需将标头从Pod导入到Bridging_Header_h中。将所需的SDK导入到您的swift文件中就足够了,例如:
import FBSDKCoreKit
import FBSDKLoginKit
import FBSDKShareKit
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句