iOS 隐私追踪

Info.plist 文件配置


NSUserTrackingUsageDescription
此标识符将用于向您发送个性化新闻及搜集崩溃信息

导入头文件


#import 
#import 


#pragma mark  --------------  适配ios14 用户隐私追踪
- (NSString*)idfa {
    
    __block NSString *idfa = @"";
    ASIdentifierManager *manager = [ASIdentifierManager sharedManager];
    if (@available(iOS 14, *)) {
        [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
            
            if (status == ATTrackingManagerAuthorizationStatusAuthorized) {
                idfa = [[manager advertisingIdentifier] UUIDString];
            }
        }];
    }else{
        if ([manager isAdvertisingTrackingEnabled]) {
            idfa = [[manager advertisingIdentifier] UUIDString];
        }
    }
    
    return idfa;
}


如果审核未通过可以增加一个弹窗


  // 根据需求,此方法写在appdelegate中,根据AppStore里面的测试账号信息进行判断弹窗,保证只有审核人员每次都弹窗,应对审核,根据账号信息判断的情况会有几个判断

// 1、第一次安装程序,此时未登录信息,应该弹窗
// 2、结束程序进程,再一次进入程序,此时未登录信息,不弹窗,因为用户可能一直不登录,如果每次都弹窗,用户体验不好,而App审核人员他第一次可能就直接登录了,多次重启登录的次数少,所以此处以考虑线上用户为主
// 3、登录账号信息,如果是测试账号,如果未同意追踪,每次重启app都弹窗
// 4、登录账号信息,如果不是测试账号,如果未同意追踪,每次重启app不弹窗



#pragma mark  --------------  适配ios14 用户隐私追踪
- (NSString*)idfa {
    
    __block NSString *idfa = @"";
    ASIdentifierManager *manager = [ASIdentifierManager sharedManager];
    if (@available(iOS 14, *)) {
        [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
            
            
            if (status == ATTrackingManagerAuthorizationStatusAuthorized) {
                idfa = [[manager advertisingIdentifier] UUIDString];
            }
                
            // att
            if (status == ATTrackingManagerAuthorizationStatusDenied || status == ATTrackingManagerAuthorizationStatusNotDetermined) {

                // 账户信息 
                NSString * phone = 本地保存的账户信息
               
                NSString * trackingTransparencyFlag = [[NSUserDefaults standardUserDefaults] objectForKey:启动标识];

                // 如果已经启动过app
                if ([trackingTransparencyFlag isEqualToString:@"1"]) {
                    // appStore账号处理
                    if ([phone isEqualToString:AppStore测试账号] ) {
                        //弹框提醒
                        [self showAttSetTips];
                    }

                } else {

                    // appStore账号处理
                    if ([phone isEqualToString:AppStore测试账号]) {
                        //弹框提醒
                        [self showAttSetTips];
                    }

                }

            }
        }];
    }else{
        if ([manager isAdvertisingTrackingEnabled]) {
            idfa = [[manager advertisingIdentifier] UUIDString];
        }
    }
    
    
    // 设置启动标识
    [[NSUserDefaults standardUserDefaults] setValue:@"1" forKey:启动标识];
    
    
    return idfa;
}

- (void)showAttSetTips{
    
    [[NSUserDefaults standardUserDefaults] setValue:@"NO" forKey:@"attseting"];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"允许“你应用名字”跟踪您在其他公司的App和网站上的活动吗?" message:@"该标识符将用于产品性能和错误日志收集、个性化广告投放。" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *cancelBtn = [UIAlertAction actionWithTitle:@"要求APP不跟踪" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {        NSLog(@"取消");
        }];    //添加确定
        UIAlertAction *sureBtn = [UIAlertAction actionWithTitle:@"允许跟踪" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull   action) {
            // 允许跟踪
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:^(BOOL success) {
                
            }];
            
        }];
        [alertVc addAction:cancelBtn];
        [alertVc addAction:sureBtn];
        [[self topViewController] presentViewController:alertVc animated:YES completion:nil];
    });
    
}

你可能感兴趣的:(iOS 隐私追踪)