delphiXE IOS编程零碎1-沙盒(沙箱)

delphiXE IOS编程零碎1-沙盒(沙箱)

一、

uses iOSapi.Foundation, iOSapi.Helpers   //2019-07-22临时添加:IOS运行时刻库等

  , Macapi.Helpers ,iOSapi.UIKit
  , iOSapi.CoreGraphics, FMX.Helpers.iOS   ;

二、

{$IFDEF IOS}
function addSkipBackupAttributeToItemAtPath(const Path1: String;const AInfoPlistPermission:NSString): Boolean;
// 不要备份到 iCloud by Aone
var Dir: NSString;
    Url: NSURL;
    ErrorPtr: Pointer;
begin
  Dir := StrToNSStr(Path1);
  //:获取路径NSString下的文件NSURL:
  Url := TNSURL.Wrap(TNSURL.OCClass.fileURLWithPath(Dir));
  //设置并返回文件的访问权限:
  Result := Url.setResourceValue(TNSNumber.OCClass.numberWithBool(True), AInfoPlistPermission, @ErrorPtr);
//参考: https://www.cnblogs.com/onechen/p/5935579.html
  // https://www.cnblogs.com/onechen/p/5290730.html
  // https://www.cnblogs.com/onechen/p/5251567.html
  // https://www.cnblogs.com/onechen/category/612780.html
  // https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html
//参数AInfoPlistPermission:
//1、先决条件,当Project->Options->Version Info应当设置的字典>值:
//2、通过类似上述代码配置资源运行时的数值:TNSURL.Wrap 、Url.setResourceValue
//3、plist中各key含义及其使用条件:
//3.01、NSURLIsExcludedFromBackupKey: 文件共享时,NSURL拒绝备份某个路径:
  //当添加了key: UIFileSharingEnabled, value:true时生效
//3.02、NSURLPathKey: NSURL获取路径:
//3.03、NSURLFileSecurityKey: NSURL文件安全键值:
//3.04、NSURLIsExecutableKey: NSURL可执行:
//3.05、NSURLIsReadableKey: NSURL可读:
//3.06、NSURLIsWritableKey: NSURL可写:
//3.07、NSURLVolumeIdentifierKey: NSURL卷标可访问:
//3.08、NSURLVolumeIdentifierKey: NSURL卷标可访问:
//3.09、NSSupportsPurgeableLocalStorage: 声明应用程序可以依赖于非本地存储来获取用户数据
//3.10、NSUbiquitousContainers: 指定本机所有APP沙盒容器在iCloud Drive云盘中的标识名
//3.11、NSUbiquitousContainerIsDocumentScopePublic: 指定iCloud驱动器是否应共享此容器的内容。默认为NO。
//3.12、NSUbiquitousContainerName: 指定iCloud Drive为容器显示的名称。默认情况下,iCloud Drive将使用拥有容器的捆绑包的名称。
//3.13、NSUbiquitousContainerSupportedFolderLevels: 指定容器的Documents目录中的最大文件夹级别数
//3.14、NSUbiquitousDisplaySet: 包含您在iTunesConnect中配置的用于管理应用程序存储的标识符字符串
//3.15、NSUserActivityTypes:指定应用程序支持的用户Activity活动类型

end;
{$ENDIF IOS}

 

三、越狱与路径的关系

1、通过AppStore或iTunes安装的App: 

      在IOS中,应用的一般安装位置位于:
      /private/var/containers/Bundle/Application
      /private/var/mobile/Containers/Bundle/Application/
      你可以使用MobaXterm通过SSH链接,之后找到对应的目录

delphiXE IOS编程零碎1-沙盒(沙箱)_第1张图片

      之后你可以根据上面的时间链进行判断,同时你可以打开该目录查看app是否对应你自己的安装的APP的名称,例如:

delphiXE IOS编程零碎1-沙盒(沙箱)_第2张图片

      APP 的数据目录大都存储在 "/private/var/mobile/Containers/Data/Application/"。如果是 root 权限运行的应用数据目录在这:"/var/root/"

      APP 大部分以 mobile 身份运行。如果想以 root 权限 运行你的 APP ,可以参考这里

 

      沙盒的使用,包括写入沙盒, 读取沙盒, 删除沙盒

      // 写入沙盒
      - (void)writeReadArrPlistWithDataArr:(NSMutableArray *)dataArr {
      NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
      NSString *docuPath = [path stringByAppendingPathComponent:bidPath]; // 获取沙盒路径
      NSLog(@"docuPath: %@",docuPath);
      BOOL b = [dataArr writeToFile:docuPath atomically:YES];
      b ? NSLog(@"写入沙盒成功") : NSLog(@"写入沙盒失败");
      }

      // 读取沙盒文件
      - (void)readReadArrPlist {
      NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
      NSString *docuPath = [path stringByAppendingPathComponent:bidPath];
      mReadArr = [NSMutableArray arrayWithContentsOfFile:docuPath];
      if (!mReadArr) {
      mReadArr = [NSMutableArray arrayWithCapacity:0];
      }
      }

      // 删除沙盒中的文件
      - (void)deleteReadArrPlist {
      NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
      NSString *docuPath = [path stringByAppendingPathComponent:bidPath];
      NSFileManager *fileManager = [NSFileManager defaultManager];
      [fileManager removeItemAtPath:docuPath error:nil];
      }

2、iOS 越狱不代表沙盒(sandbox)的移除

3、越狱后App能获得应用文件夹(/var/mobile/Aplications/)的读写权限,可遍历其下的App路径下的信息

4、原本的一些私密文件,比如短信资料(/var/mobile/Library/SMS/sms.db),即便是通过AppStore安装的App仍旧没有访问权限

5、苹果对沙盒有几条限制:

5.1. 应用程序在自己的沙盒中运作,但是不能访问任何其他应用程序的沙盒;
5.2. 应用之间不能共享数据,沙盒里的文件不能被复制到其他应用程序的文件夹中,也不能把其他应用文件夹复制到沙盒中;
5.3. 苹果禁止任何读写沙盒以外的文件,禁止应用程序将内容写到沙盒以外的文件夹中;
5.4. 沙盒目录里有三个文件夹:
    Documents——存储应用程序的数据文件,存储用户数据或其他定期备份的信息;
    Library下有两个文件夹,Caches存储应用程序再次启动所需的信息,Preferences包含应用程序的偏好设置文件,不可在这更改偏好设置;
    temp存放临时文件即应用程序再次启动不需要的文件。

四、iPhone越狱后,常见路径大全

感谢网友分享:

   https://blog.csdn.net/HK_5788/article/details/51236370 

 

 

 

 

 

 

你可能感兴趣的:(delphi,App开发,IOS)