iOS隐私安全:用户协议及隐私政策弹框(包含超链接属性、demo支持中英文切换)

简介: iOS隐私安全:用户协议及隐私政策弹框(包含超链接属性、demo支持中英文切换)

前言

熟悉监管要求,掌握合规操作流程,避免App被降级或者下架。需要确保App有《隐私政策》,并且在用户首次启动App时就弹出《隐私政策》取得用户同意。

登录界面弹用户协议及隐私政策时,如果用户点击不同意,不能停留在弹框界面,需要隐藏弹框,否则无法通过OPPO安卓应用市场。

image.png

用户协议及隐私政策》 弹框的实现步骤:

1、自定义TextView,采用富文本属性进行内容设置attributedText(包括下划线NSUnderlineStyleSingle、超链接NSLinkAttributeName 、颜色NSForegroundColorAttributeName 等信息) 2、实现代理方法textView:shouldInteractWithURL:inRange,处理点击超链接的回调(打开对应URL Webview)

  • 效果图(点击demo的右上架文字进行中英文切换

image.png

image.png

  • 文本框信息对应的中英文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

从csdn资源下载demo源码:https://download.csdn.net/download/u011018979/14026773

CSDN文章:https://kunnan.blog.csdn.net/article/details/103902362

获取资源下载链接

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;
  • 设置下划线和颜色
  [attrStr setAttributes:@{NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle)}
                     range:str4Range];
    [attrStr addAttribute:NSFontAttributeName value:kPingFangFont(13) range:str4Range];
    [attrStr addAttribute:NSForegroundColorAttributeName value:HWColor(6, 53, 253) range:str4Range];

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


目录
相关文章
|
27天前
|
存储 运维 安全
iOS加固原理与常见措施:保护移动应用程序安全的利器
iOS加固原理与常见措施:保护移动应用程序安全的利器
28 0
|
3月前
|
安全 前端开发 iOS开发
钉钉里微应用ios 底部安全区域的颜色怎么修改?
钉钉里微应用ios 底部安全区域的颜色怎么修改?
55 5
|
3月前
|
存储 运维 安全
iOS加固原理与常见措施:保护移动应用程序安全的利器
iOS加固原理与常见措施:保护移动应用程序安全的利器
38 0
|
3月前
|
iOS开发
iOS App Store 上传项目报错 缺少隐私政策网址 (URL) 解决方法
iOS App Store 上传项目报错 缺少隐私政策网址 (URL) 解决方法
iOS App Store 上传项目报错 缺少隐私政策网址 (URL) 解决方法
|
3月前
|
存储 Linux iOS开发
iOS 技术博主指南:填写苹果应用上架中的隐私政策信息
iOS 技术博主指南:填写苹果应用上架中的隐私政策信息
|
5月前
|
运维 安全 数据安全/隐私保护
iOS加固原理与常见措施:保护移动应用程序安全的利器
随着移动应用的普及和用户对数据安全的关注度提高,iOS加固成为了很多开发者和企业的必备工具。那么,iOS加固是如何保护应用程序的安全性的呢? iOS加固是指对OS应用程序进行一系列的安全措施,以提高其抗逆向工程、反编译和破解的能力。下面将介绍iOS加固的原理和常见的加固措施。
iOS加固原理与常见措施:保护移动应用程序安全的利器
|
7月前
|
iOS开发
iOS 多个滚动控件嵌套Demo
iOS 多个滚动控件嵌套Demo
38 0
|
7月前
|
iOS开发
iOS UIKit Dynamics Demo 学习地址列表
iOS UIKit Dynamics Demo 学习地址列表
23 0
|
7月前
|
iOS开发
倒计时15分钟-兼容ios手机效果demo(整理)
倒计时15分钟-兼容ios手机效果demo(整理)