美文网首页
iOS Facebook AppEvents SDK 接入记录

iOS Facebook AppEvents SDK 接入记录

作者: IT言 | 来源:发表于2024-03-26 13:33 被阅读0次

    1、事件管理工具【查看详情】可以看到数量 ,但是查看近期事件无记录
    如果Facebook sdk 显示在14.0.1及以下,尝试升级版本到最新版本16.3.1
    并将以下代码添加置info.plist

    <key>FacebookAdvertiserIDCollectionEnabled</key>
        <false/>
        <key>FacebookAutoInitEnabled</key>
        <true/>
        <key>FacebookAutoLogAppEventsEnabled</key>
        <true/>
    

    在初始化sdk位置添加以下调用

        [[FBSDKSettings sharedSettings] setIsAutoLogAppEventsEnabled:YES];
        [[FBSDKSettings sharedSettings] setIsAdvertiserTrackingEnabled:YES];
        [[FBSDKSettings sharedSettings] setIsAdvertiserIDCollectionEnabled:YES];
    

    在applicationDidBecomeActive和sceneDidBecomeActive添加以下调用

    if (@available(iOS 14, *)) {
           dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
               [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
                   NSLog(@"ATT status:%lu", (unsigned long)status);
                   switch (status) {
                       case ATTrackingManagerAuthorizationStatusAuthorized:
                           {
                               [[FBSDKSettings sharedSettings] setIsAdvertiserTrackingEnabled:YES];
                           }
                           break;
                       case ATTrackingManagerAuthorizationStatusDenied:
                       {
                           [[FBSDKSettings sharedSettings] setIsAdvertiserTrackingEnabled:NO];
                       }
                           break;
                       default:
                           break;
                   }                
               }];
           });
       } else {
                 [[FBSDKSettings sharedSettings] setIsAdvertiserTrackingEnabled:YES];
       }
    

    根据需求可以打开Facebook sdk log 查看错误日志

            [[FBSDKSettings sharedSettings] enableLoggingBehavior:FBSDKLoggingBehaviorNetworkRequests];
            [[FBSDKSettings sharedSettings] enableLoggingBehavior:FBSDKLoggingBehaviorNetworkRequests];
            [[FBSDKSettings sharedSettings] enableLoggingBehavior:FBSDKLoggingBehaviorAppEvents];
            [[FBSDKSettings sharedSettings] enableLoggingBehavior:FBSDKLoggingBehaviorAccessTokens];
            [[FBSDKSettings sharedSettings] enableLoggingBehavior:FBSDKLoggingBehaviorCacheErrors];
            [[FBSDKSettings sharedSettings] enableLoggingBehavior:FBSDKLoggingBehaviorDeveloperErrors];
    

    还可以尝试在合适的时机重新调用Facebook sdk 的初始化方法

        [[FBSDKApplicationDelegate sharedInstance] initializeSDK];
    

    最后就是按步骤检查文档接入流程是否有缺失(以app events接入为例)

    对于iOS14.5+机型,未开启AdvertiserTrackingEnabled 将无法上传事件,在近期事件中应该是看不到的,

    在事件管理工具中测试事件时

    1.一定要保证ATT 自己的应用和facebook都已开启
    2.网络正常
    3.facebook登录开发者账号
    

    相关文章

      网友评论

          本文标题:iOS Facebook AppEvents SDK 接入记录

          本文链接:https://www.haomeiwen.com/subject/dcvdtjtx.html