【问题标题】:2.23 Apps must follow the iOS Data Storage Guidelines or they will be rejected2.23 应用程序必须遵循 iOS 数据存储指南,否则将被拒绝
【发布时间】:2012-12-02 07:23:17
【问题描述】:

我正在阅读很多关于这个问题的问题。我正在为我的应用程序使用 Phonegap。 我的应用程序下载了大约 3mb 的图像。 Apple 拒绝我的应用并建议对所有文件应用“不备份属性”。How do I prevent files from being backed up to iCloud and iTunes?

我将此代码用于我的 5.1 应用程序:

- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
 {
      assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);

      NSError *error = nil;
      BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES]
                              forKey: NSURLIsExcludedFromBackupKey error: &error];
      if(!success){
         NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
      }
      return success;
 }

我把它放在我的 AppDelegate.m 中。对吗?

【问题讨论】:

  • 我想补充一点,所有文件都在“/var/mobile/Applications/CEEECEA6-4684-4599-B0BF-407BE2CBD3CE/Library/Caches/”中

标签: ios objective-c cordova appstore-approval


【解决方案1】:

您现在将文件存储在哪里?我猜你是在使用标准的 Phonegap 示例:

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onSuccess, null);

一种解决方案是使用以下代码处理您的 FileSytem 请求,这将重新获取您应用的临时目录:

window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, onSuccess, onError);

iOS 上的 LocalFileSystem.TEMPORARY 将指向

/var/mobile/Applications/CEEECEA6-4684-4599-B0BF-407BE2CBD3CE/tmp

亲切的问候,

迈克

【讨论】:

  • 我使用 PERSISTENT 因为我需要让我的数据离线。在 tmp 文件夹中,我丢失了所有数据。我读到如果我将数据放入库/缓存中,iCloud 将忽略它。但 Apple 拒绝了我的应用。
  • 只有当您运行的设备数据不足时,您在 /tmp 文件夹中的数据才会被删除。缓存也一样...
  • 好的,我正在 /var/mobile/Applications/CEEECEA6-4684-4599-B0BF-407BE2CBD3CE/tmp 中修改我的路径。但是,当我检查时 - 转到设置 > iCloud > 存储和备份 > 管理存储并检查我的应用程序的存储空间,仍然是 2.3 MB。
  • 好的,你可以使用 Javascript 来设置 com.apple.MobileBackup 属性,就像这样 parent.setMetadata(onSetMetadataSuccess, onSetMetadataFail, { "com.apple.MobileBackup": 1});更多信息stackoverflow.com/questions/10085653/…
【解决方案2】:

这是我的代码

   var DATADIR;
   var knownfiles = []; 

   function init() {
         document.addEventListener("deviceready", onDeviceReady, true);
   }

   function onDeviceReady() {
          window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFSSuccess, null);    
    }

    //Loaded my file system, now let's get a directory entry for where I'll store my crap    
    function onFSSuccess(fileSystem) {
         fileSystem.root.getDirectory("it.mns.dcsofficebp",{create:true},gotDir,onError);
    }

    //The directory entry callback
    function gotDir(d){
         DATADIR = d;
         var reader = DATADIR.createReader();
         localStorage.setItem("datadir",JSON.stringify(DATADIR));
         reader.readEntries(function(d){
             appReady();
         },onError);
    }

     //Result of reading my directory
     function gotFiles(entries) {
         for (var i=0; i<entries.length; i++) {
                knownfiles.push(entries[i].name);
                renderPicture(entries[i].fullPath);
          }
      }

我需要放在哪里

parent.setMetadata(onSetMetadataSuccess, onSetMetadataFail, { "com.apple.MobileBackup": 1});

【讨论】:

    【解决方案3】:

    这应该是在我身边工作的正确代码:

    var DATADIR;
    var knownfiles = []; 
    
    function init() {
              window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFSSuccess, null);
    }
    
    function onFSSuccess(fileSystem) {
        console.log("here I am");
        fileSystem.root.getDirectory("it.mns.dcsofficebp",{create:true},gotDir,false);
    }
    function gotDir(d){
        DATADIR = d;
        DATADIR.setMetadata(onSetMetadataSuccess, onSetMetadataFail, { "com.apple.MobileBackup": 1});
    }
    
    function onSetMetadataSuccess() {
        console.log("success setting metadata - DONE DONE DONE!")
    }
    function onSetMetadataFail() {
        console.log("error setting metadata")
    }
    

    这是我的结果:2012-12-14 12:46:20.064 testproj[1779:c07] [LOG] 成功设置元数据 - DONE DONE DONE!

    【讨论】:

    • 我正在尝试您的示例。但停止使用此消息:2012-12-14 12:32:39.676 dcsofficebp[3027:907] [INFO] 成功回调错误:File2 = TypeError: 'undefined' is not a function
    • 尝试将DATADIR.setMetadata(设置为d.setMetadata
    • 另外,{ "com.apple.MobileBackup": 0} 必须是 { "com.apple.MobileBackup": 1}
    • 相同的错误代码。如果可以帮助您,我将添加 console.log(DATADIR) 并打印 {"isFile":false,"isDirectory":true,"name":"it.mns.dcsofficebp","fullPath":"/var /mobile/Applications/2F2629BD-BA56-4803-97C6-7520113080A8/Documents/it.mns.dcsofficebp","filesystem":null}
    猜你喜欢
    • 2015-05-06
    • 2014-04-03
    • 1970-01-01
    • 1970-01-01
    • 2016-08-10
    • 2012-06-27
    • 2012-12-03
    • 1970-01-01
    • 2014-08-29
    相关资源
    最近更新 更多