IOS-高德地图隐私合规示例-Swift

高德地图8.1.0之后,需要设置隐私合规才能正常使用地图等功能。
正常再使用之前这样设置就行了:

import MAMapKit

MAMapView.updatePrivacyAgree(AMapPrivacyAgreeStatus.didAgree)
MAMapView.updatePrivacyShow(AMapPrivacyShowStatus.didShow, privacyInfo: AMapPrivacyInfoStatus.didContain)

为了好看一点,弄个弹窗例子(改自官方demo):

if !UserDefaults.standard.bool(forKey: "agreeStatus") {
   
            //添加隐私合规弹窗
            self.addAlertController()
            //更新App是否显示隐私弹窗的状态,隐私弹窗是否包含高德SDK隐私协议内容的状态. since 8.1.0
            MAMapView.updatePrivacyShow(AMapPrivacyShowStatus.didShow, privacyInfo: AMapPrivacyInfoStatus.didContain)
        }
        else{
   
            initMapView()
            initLocation()
            initSearch()
        }

设置弹窗:

//隐私合规窗口
    func addAlertController(){
   
        
        let paragraphStyle : NSMutableParagraphStyle = NSMutableParagraphStyle.init()
        paragraphStyle.alignment = NSTextAlignment.left
        
        let message : NSMutableAttributedString = NSMutableAttributedString.init(string: "\n亲,感谢您对XXX一直以来的信任!我们依据最新的监管要求更新了XXX《隐私权政策》,特向您说明如下\n1.为向您提供交易相关基本功能,我们会收集、使用必要的信息;\n2.基于您的明示授权,我们可能会获取您的位置(为您提供附近的商品、店铺及优惠资讯等)等信息,您有权拒绝或取消授权;\n3.我们会采取业界先进的安全措施保护您的信息安全;\n4.未经您同意,我们不会从第三方处获取、共享或向提供您的信息;", attributes: [NSAttributedString.Key.paragraphStyle:paragraphStyle])
        
        message.setAttributes([NSAttributedString.Key.foregroundColor:UIColor.blue], range: message.mutableString.range(of: "《隐私权政策》"))
        
        let alert : UIAlertController = UIAlertController.init(title: "温馨提示", message: "", preferredStyle: UIAlertController.Style.alert)
        
        alert.setValue(message, forKey: "attributedMessage")
        
        let conform : UIAlertAction = UIAlertAction.init(title: "同意", style: UIAlertAction.Style.default) {
    UIAlertAction in
            UserDefaults.standard.set(true, forKey: "agreeStatus")
            UserDefaults.standard.synchronize()
            //更新用户授权高德SDK隐私协议状态. since 8.1.0
            MAMapView.updatePrivacyAgree(AMapPrivacyAgreeStatus.didAgree)
            self.initMapView()
            self.initLocation()
            self.initSearch()
        }
        
        let cancel : UIAlertAction = UIAlertAction.init(title: "不同意", style: UIAlertAction.Style.cancel) {
    UIAlertAction in
            UserDefaults.standard.set(false, forKey: "agreeStatus")
            UserDefaults.standard.synchronize()
            //更新用户授权高德SDK隐私协议状态. since 8.1.0
            MAMapView.updatePrivacyAgree(AMapPrivacyAgreeStatus.notAgree)
        }
        
        alert.addAction(conform)
        alert.addAction(cancel)
        
        self.present(alert, animated: true, completion: nil)
    }

结果

在这里插入图片描述

相关推荐

  1. ISO Swift导航开发指南

    2024-01-17 06:16:05       17 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-17 06:16:05       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-17 06:16:05       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-17 06:16:05       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-17 06:16:05       20 阅读

热门阅读

  1. python期末考试:基本数据的表示

    2024-01-17 06:16:05       25 阅读
  2. [AIGC] Spring Boot Docker 部署指南

    2024-01-17 06:16:05       29 阅读