Tim*_*ing 7 facebook ios facebook-ios-sdk facebook-sdk-4.0 swift
我在尝试在 iOS 上安装 Facebook SDK 以进行应用程序事件分析时遇到了一场噩梦。facebook 的文档很糟糕,而且不一致,我找不到任何有效的最新安装文档。我想要做的就是安装 SDK,以便我可以跟踪应用程序安装和应用程序打开事件。我使用cocoapods进行安装
pod 'Facebook-iOS-SDK'
Run Code Online (Sandbox Code Playgroud)
在我的应用程序委托 didFinishLaunchingWithOptions 中,我有以下代码
import FBSDKCoreKit
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
ApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
Settings.isAutoLogAppEventsEnabled = true
Settings.isAdvertiserIDCollectionEnabled = true
Settings.loggingBehaviors = [LoggingBehavior.appEvents,LoggingBehavior.networkRequests]
return true
}
// ...
}
Run Code Online (Sandbox Code Playgroud)
在我的 info.plist 中,根据文档,我有以下内容:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb396923698487528</string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string>396923698487528</string>
<key>FacebookDisplayName</key>
<string>Where4Test</string>
Run Code Online (Sandbox Code Playgroud)
从日志中可以看出,分析事件已成功发送并返回至 facebook api。但在事件管理器https://www.facebook.com/events_manager2中没有显示任何事件,它说我还没有安装 SDK。
我已经尝试了一百万种不同的事情,但就是无法让事件在 Facebook 上注册。请有人提供最新的安装说明或看看我做错了什么!
该问题的解决方案是向用户请求广告跟踪权限,如下所示
\nimport AppTrackingTransparency\nimport AdSupport\n//\xe2\x80\xa6 \n\nif #available(iOS 14, *) {\n ATTrackingManager.requestTrackingAuthorization { status in\n switch status {\n case .authorized:\n // Tracking authorization dialog was shown\n // and we are authorized\n print("Authorized")\n \n // Now that we are authorized we can get the IDFA\n print(ASIdentifierManager.shared().advertisingIdentifier)\n case .denied:\n // Tracking authorization dialog was\n // shown and permission is denied\n print("Denied")\n case .notDetermined:\n // Tracking authorization dialog has not been shown\n print("Not Determined")\n case .restricted:\n print("Restricted")\n @unknown default:\n print("Unknown")\n }\n }\n}\nRun Code Online (Sandbox Code Playgroud)\nFacebook 文档并未提及这是应用程序事件正常运行所需的安装步骤,但事实证明确实如此。这不是出于任何编码原因的\xe2\x80\x99,而是出于法律合规性原因。他们确实应该说这是一个必要的步骤,并通知您,如果您没有请求授权,则 SDK 日志中不会跟踪事件。
\n