iOS用户协议及隐私政策弹框(demo支持中英文切换)
前言
熟悉监管要求,掌握合规操作流程,避免App被下架。
您需要确保App有《隐私政策》,并且在用户首次启动App时就弹出《隐私政策》取得用户同意。
《用户协议及隐私政策》 弹框的实现步骤:
效果图(1、自定义TextView,采用富文本属性进行内容设置
attributedText
(包括下划线NSUnderlineStyleSingle、超链接NSLinkAttributeName 、颜色NSForegroundColorAttributeName 等信息)2、实现代理方法
textView:shouldInteractWithURL:inRange
,处理点击超链接的回调(打开对应URL Webview)
点击demo的右上架文字进行中英文切换
)文本框信息对应的中英文key,用于本地化
"Explain3" = "向您说明,在使用我们的服务时,我们如何收集、使用、储存和分享这些信息,以及我们为您提供的访问、更新、控制和保护这些信息的方式。本"; "Wemaycollect1"="您在使用我们的服务时,我们可能会收集和使用您的相关信息。我们希望通过本"; "then_click_Agree" = " ,希望您仔细阅读,充分理解协议中的内容后再点击同意。"; "Wemaycollect1"="We may collect and use information about you when you use our services. We hope to pass this"; "Explain3"= "Explain to you how we collect, use, store and share this information and how we provide you with access, update, control and protection when using our services. this"; "then_click_Agree"= " , I hope you read it carefully, fully understand the content of the agreement, and then click Agree.";
从csdn资源下载demo源码:https://download.csdn.net/download/u011018979/14026773
I、 自定义TextView: QCTTextViewHyperLink
采用富文本属性进行内容设置attributedText
1.0 demo源码
从csdn资源下载demo源码:https://download.csdn.net/download/u011018979/14026773
CSDN文章:https://kunnan.blog.csdn.net/article/details/103902362demo源码 : 存放在GitHub私有仓库demo源码 : csdn私有仓库
1.1 采用富文本属性进行内容设置
attributedText
新增超链接属性包括下划线NSUnderlineStyleSingle、超链接NSLinkAttributeName 、颜色NSForegroundColorAttributeName 等信息
[attrStr addAttribute:NSLinkAttributeName value:k_serviceAgreement_URL range:str4Range]; [attrStr addAttribute:NSLinkAttributeName value:k_serviceAgreement_URL range:str2Range]; tmp.editable = NO; tmp.attributedText = attrStr;//text tmp.selectedRange = NSMakeRange(attrStr.length, 0); tmp.delegate = self; tmp.userInteractionEnabled = YES;
设置下划线和颜色
range:str4Range]; [attrStr addAttribute:NSFontAttributeName value:kPingFangFont(13) range:str4Range]; [attrStr addAttribute:NSForegroundColorAttributeName value:HWColor(6, 53, 253) range:str4Range]; [attrStr setAttributes:@{NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle)}
1.2 实现代理方法
处理点击超链接的回调(打开对应URL Webview)- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange {
/** 代理方法 */ - (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange { __weak __typeof__(self) weakSelf = self; if([URL.absoluteString isEqualToString:k_serviceAgreement_URL]){ [self.viewModel.hiddenQCTserviceAgreementViewSubject sendNext:nil]; void (^showQCTserviceAgreementViewBlock)(id sender) = ^void(id sender) { NSLog(@"nil"); // 展示 [weakSelf.viewModel.showQCTserviceAgreementViewSubject sendNext:nil]; }; [self.viewModel.User_Agreement_and_Privacy_PolicySubject sendNext:showQCTserviceAgreementViewBlock]; } // return NO; }
II、封装《用户协议及隐私政策》视图
获取带有富文本字符串的TextView视图// QCTTextViewHyperLink.m // retail // // Created by mac on 2020/1/9. // Copyright 2020 QCT. All rights reserved. // #import "QCTTextViewHyperLink.h" @implementation QCTTextViewHyperLink /** 获取 《用户协议及隐私政策》的数据 @return《用户协议及隐私政策》的数据 */ + (instancetype)getserviceAgreemenTextView{ QCTTextViewHyperLink * tmp = [QCTTextViewHyperLink new]; NSString *str1 = QCTLocal(@"Wemaycollect1"); NSString *str2 = [NSString stringWithFormat:@"《%@》",QCTLocal(@"Service_Agreement4User")]; NSString *str3 = QCTLocal(@"Explain3"); NSString *str4 = [NSString stringWithFormat:@"《%@》",QCTLocal(@"Service_Agreement4User")]; NSString *str5 = QCTLocal(@"then_click_Agree"); NSString *str = [NSString stringWithFormat:@"%@%@%@%@%@",str1,str2,str3,str4,str5]; //1、 设置富文本属性 NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:str]; [attrStr addAttribute:NSFontAttributeName value:kPingFangFont(13) range:NSMakeRange(0 ,attrStr.length)]; [attrStr addAttribute:NSForegroundColorAttributeName value:HWColor(51, 51, 51) range:NSMakeRange(0 ,attrStr.length)]; // 2、设置行lineSpacing NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new]; paragraphStyle.lineSpacing = 5; NSMutableDictionary *attributes = [NSMutableDictionary dictionary]; [attributes setObject:paragraphStyle forKey:NSParagraphStyleAttributeName]; [attrStr addAttributes:attributes range:NSMakeRange(0, attrStr.length)]; // NSParagraphStyle defaultParagraphStyle //3、设置下划线和颜色 NSRange str2Range = NSMakeRange(str1.length, str2.length ); NSRange str4Range = NSMakeRange(str1.length+str2.length+str3.length, str4.length ); [attrStr setAttributes:@{NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle)} range:str2Range]; [attrStr addAttribute:NSFontAttributeName value:kPingFangFont(13) range:str2Range]; [attrStr addAttribute:NSForegroundColorAttributeName value:HWColor(6, 53, 253) range:str2Range]; [attrStr setAttributes:@{NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle)} range:str4Range]; [attrStr addAttribute:NSFontAttributeName value:kPingFangFont(13) range:str4Range]; [attrStr addAttribute:NSForegroundColorAttributeName value:HWColor(6, 53, 253) range:str4Range]; //4、新增超链接属性 [attrStr addAttribute:NSLinkAttributeName value:k_serviceAgreement_URL range:str4Range]; [attrStr addAttribute:NSLinkAttributeName value:k_serviceAgreement_URL range:str2Range]; tmp.editable = NO; tmp.attributedText = attrStr;//text tmp.selectedRange = NSMakeRange(attrStr.length, 0); // tmp.userInteractionEnabled = YES; return tmp; } // 继承UITextView重写这个方法 - (BOOL)canPerformAction:(SEL)action withSender:(id)sender { // 返回NO为禁用,YES为开启 // 粘贴 if (action == @selector(paste:)) return NO; // 剪切 if (action == @selector(cut:)) return NO; // 复制 if (action == @selector(copy:)) return NO; // 选择 if (action == @selector(select:)) return NO; // 选中全部 if (action == @selector(selectAll:)) return NO; // 删除 if (action == @selector(delete:)) return NO; // 分享 if (action == @selector(share)) return NO; return [super canPerformAction:action withSender:sender]; } @end//
III、Q&A
3.1 为什么我下载demo后,在xcode12中允许报错:library not found for -lAXIndicatorView;请问怎么解决?
原因:这是找不到 CocoaPods库 AXIndicatorView。是 AXWebViewController库依赖于它
解决方法: 你更新 pod "AXWebViewController" 即可。
1、只更新指定的库,其它库忽略:
pod update AXWebViewController --verbose --repo-update
2、pod update会更新所有的类库,获取最新版本的类库
cocoapods 用法文章:https://blog.csdn.net/z929118967/article/details/103830017
#!/bin/sh #该命令只安装新添加的库,已更新的库忽略 pod install --verbose --no-repo-update #该命令只更新指定的库,其它库忽略 #pod update 库名 --verbose --no-repo-update exit 0% retail git:(develop) exit 0% retail git:(develop) cat ~/bin/knpod
3.2 在hbuilder打包好ipa包了,需要隐私弹窗的解决方案
方案一:写webview形式的弹框/nvue
方案二:利用js 和OC的交互,在需要弹窗的地方,调用已经封装好的OC方法即可
具体请看这篇文章的第三部分https://kunnan.blog.csdn.net/article/details/115673455
基于HBuilder iOS离线打包widget方式 js 调oc 的参考代码
js调用原生oc方法
plus.ios.importClass("LoginViewController").login("txt“);//LoginViewController是oc类 txt是要传的参数
js调用oc对象方法
var Massage = plus.ios.importClass("LoginViewController"); var massage = new Massage(); var massageArray = massage.objectToJsonImage();//objectToJsonImage是oc对象方法 massageArray返回值
IV、see also
更多内容请关注#小程序:iOS逆向
,只为你呈现有价值的信息,专注于移动端技术研究领域。
NSUnderlineStyleSingle 下划线和颜色
[attrStr setAttributes:@{NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle)} range:str2Range]; [attrStr addAttribute:NSFontAttributeName value:kPingFangFont(13) range:str2Range]; // [attrStr addAttribute:NSForegroundColorAttributeName value:HWColor(50, 172, 255) range:str2Range]; [attrStr addAttribute:NSForegroundColorAttributeName value:HWColor(6, 53, 253) range:str4Range]; [attrStr setAttributes:@{NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle)} range:str4Range]; [attrStr addAttribute:NSFontAttributeName value:kPingFangFont(13) range:str4Range]; [attrStr addAttribute:NSForegroundColorAttributeName value:HWColor(6, 53, 253) range:str4Range];
4.3 传递block参数
传递block参数 NSLog(@"nil"); }; [self.viewModel.User_Agreement_and_Privacy_PolicySubject sendNext:showQCTserviceAgreementViewBlock]; void (^showQCTserviceAgreementViewBlock)(id sender) = ^void(id sender) {
使用block参数
@strongify(self); // [self jumpRegistered]; if(block){ block(nil); } }]; [self.viewModel.User_Agreement_and_Privacy_PolicySubject subscribeNext:^(void (^block)(id sender)) {