在Swift 3中显示Facebook活动,可以通过以下步骤实现:
application(_:didFinishLaunchingWithOptions:)
方法中添加以下代码:import FBSDKCoreKit
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
return true
}
import FBSDKCoreKit
import FBSDKLoginKit
func getFacebookEvents() {
let request = FBSDKGraphRequest(graphPath: "/me/events", parameters: nil)
request?.start(completionHandler: { (connection, result, error) in
if let error = error {
print("Error: \(error.localizedDescription)")
} else if let result = result as? [String: Any] {
if let events = result["data"] as? [[String: Any]] {
for event in events {
if let eventName = event["name"] as? String {
print("Event Name: \(eventName)")
}
}
}
}
})
}
这是一个基本的示例,你可以根据你的需求进行扩展和定制。请注意,上述代码仅用于演示目的,实际使用时可能需要处理更多的错误和边界情况。
领取专属 10元无门槛券
手把手带您无忧上云