zoukankan      html  css  js  c++  java
  • iOS 开启data protection 的方法

    我这里说的data protection,指的是设备设置密码后,如果设备锁屏,并且当前解锁需要密码(有时可能因为自己的设定,导致会再几小时后才需要密码),这时应用程序处于加密状态,无法从外部读取。如果开了iTurns 的文件夹访问功能,具体的表现就是无法拖出文件了,会提示没有权限。

    我们的修改是在xcode中的工程配置中的capabilities页面进行的,这里面的各个设置打开后,xcode做的操作并不相同,会在下面用小字提示。比如启用后台音乐播放是对info.plist进行操作,而打开Data protection却需要修改apple id 的属性,并下载新的provisioning file!

    最近做了一款程序,需要后台播放音乐,结果发现如果锁屏切需要密码解锁了,音乐会被data protection功能组织继续访问,结果音乐就停了,所以开始研究具体解决方法。

    网上有一种修改文件保护属性的方法,就是通过NSFileManager的

    - (BOOL)setAttributes:(NSDictionary *)attributes
             ofItemAtPath:(NSString *)path
                    error:(NSError **)error

    方法,来设定文件夹属性,进而达到目的。可能在ios7或ios6以前,这种方法是好用的,目前这个方法的说明如下

    attributes    
    A dictionary containing as keys the attributes to set for path and as values the corresponding value for the attribute. You can set the following attributes: NSFileBusy, NSFileCreationDate, NSFileExtensionHidden, NSFileGroupOwnerAccountID, NSFileGroupOwnerAccountName, NSFileHFSCreatorCode, NSFileHFSTypeCode, NSFileImmutable, NSFileModificationDate, NSFileOwnerAccountID, NSFileOwnerAccountName, NSFilePosixPermissions. You can change single attributes or any combination of attributes; you need not specify keys for all attributes.

    注意这里允许修改的属性中,根本没有NSFileProtectionKey这个属性,所以这个方法现在是不好用的!NSFileProtectionKey这个属性我理解是只读的,方便用户获取当前文件保护属性。

    我们看看新xcode中关于data protection 的设定画面

     

    可以看到下方的文字,说明这个选项直接和apple id的配置相关。

    我们再看看apple id 的设定,如下图

    正好对应了在nsfilemanager中声明的3中加密模式!

  • 相关阅读:
    nginx:安装成windows服务
    org.aspectj.apache.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 18
    数据库中间件
    架构策略
    谈判
    设计模式 总结 常用10种
    08 状态模式 state
    07 策略模式 strategy
    06 命令模式(不用)
    05 观察者模式 Observer
  • 原文地址:https://www.cnblogs.com/breezemist/p/4426368.html
Copyright © 2011-2022 走看看