美文网首页
appsflyer广告营销SDK集成遇坑

appsflyer广告营销SDK集成遇坑

作者: ttdiOS | 来源:发表于2024-06-25 18:04 被阅读0次

    产品说boss要对接appsflyer sdk

    遇到了不少坑这里记录下:

    在app联网时调用这个初始化

         {

                        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

                            [[AppsFlyerLib shared] setAppsFlyerDevKey:kAppsFlyerDevKey];

                            [[AppsFlyerLib shared] setAppleAppID:kAppleID_str];

                            [AppsFlyerLib shared].shouldCollectDeviceName =YES;

                            [[AppsFlyerLib shared] setDelegate:self];

                            [[AppsFlyerLib shared] setDeepLinkDelegate:self];

                            // 20230606 // 20230606 AppsFlyer需要确保用户已经明确授权App跟踪。这个方法可能是用来延迟初始化SDK,直到用户授权跟踪发生。这个waitForATTUserAuthorizationWithTimeoutInterval很重要要不然afid会拿不到

                            [[AppsFlyerLib shared] waitForATTUserAuthorizationWithTimeoutInterval:120];

                            //

                            [[AppsFlyerLib shared] start];

                        });

                    }

    遵守代理:

    - (void)didResolveDeepLink:(AppsFlyerDeepLinkResult *)result {

        switch(result.status) {

            case AFSDKDeepLinkResultStatusNotFound:

                NSLog(@"555-not found");

    //            [CommonUtil showCommonToastWithStr:@"新安装数据 not found" hideAfterSeconds:2 andAfterPostAction:nil postObject:nil];

                break;

            case AFSDKDeepLinkResultStatusFailure:

                NSLog(@"555-link failure");

    //            [CommonUtil showCommonToastWithStr:@"新安装数据 link failure" hideAfterSeconds:2 andAfterPostAction:nil postObject:nil];

                break;

            case AFSDKDeepLinkResultStatusFound:

                NSLog(@"555-link found");

                break;

            default:

                break;

        }

        AppsFlyerDeepLink*deepLink =  (AppsFlyerDeepLink *)result.deepLink;

    //    deepLink.campaignId

        NSString*str =  [deepLinktoString];

        NSLog(@"str555:%@",str);

        //po deepLink

    //    {"af_sub4":"","click_http_referrer":"","af_sub1":"","click_event":{"af_sub4":"","click_http_referrer":"","af_sub1":"","af_sub3":"","deep_link_value":"xxxticketxxx,xxxuidxxx","campaign":"","match_type":"probabilistic","af_sub5":"","campaign_id":"","media_source":"","af_sub2":""},"af_sub3":"","deep_link_value":"xxxticketxxx,xxxuidxxx","campaign":"","match_type":"probabilistic","af_sub5":"","media_source":"","campaign_id":"","af_sub2":""}

        if(deepLink !=nil) {

            // AppsFlyerDeepLink

            NSString*mydeeplinkValue =  deepLink.deeplinkValue;

            NSString*mymediaSource = deepLink.mediaSource;

            NSString*campaignId = deepLink.campaignId;

    //        [CommonUtil showCommonToastWithStr:[NSString stringWithFormat:@"新安装拿到数据:%@",mydeeplinkValue] hideAfterSeconds:2 andAfterPostAction:nil postObject:nil];

            if(mydeeplinkValue) {

                [[NSUserDefaultsstandardUserDefaults]setObject:mydeeplinkValueforKey:@"AFDeepLinkValue"];

    //            [self.afLinkBindReq zzAFLinkBind];

                [[AuditingManager sharedInstance]getAuditingNet:^{

                    [BRAppDelegatehideHUD];

                    if(![CommonUtilisXPLogined] && [CommonUtilisPassDeviceLogin]) {

                        [[NSNotificationCenter defaultCenter]postNotificationName:@"extendDeviceLog" object:nil];

                        NSLog(@"postNotificationName:------extendDeviceLog");

                    }

                }];

            }

            if(mymediaSource) {

                [[NSUserDefaultsstandardUserDefaults]setObject:mymediaSourceforKey:@"AFMediaSource"];

            }

            [[NSUserDefaults standardUserDefaults] synchronize];

        }else{

            [[AuditingManager sharedInstance]getAuditingNet:^{

                [BRAppDelegatehideHUD];

                if(![CommonUtilisXPLogined] && [CommonUtilisPassDeviceLogin]) {

                    [[NSNotificationCenter defaultCenter]postNotificationName:@"refreshDeviceUI" object:nil];

                }

            }];

        }

    }

    若是还是拿不到网页点进来的 回调(上方的dele方法:DeepLinkDelegate)

    那么就让web人员在链接里加上:固定格式,必须带:af_force_deeplink=true&deep_link_sub1-10=2

    相关文章

      网友评论

          本文标题:appsflyer广告营销SDK集成遇坑

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