【问题标题】:How to download file to machine without storing information on iCloud?如何在不将信息存储在 iCloud 上的情况下将文件下载到机器?
【发布时间】:2012-06-12 05:57:44
【问题描述】:

如何下​​载文件而不将信息存储在 iCloud 上?

我的应用程序是下载pdf到机器的应用程序。它被Apple拒绝,原因是“特别是,我们发现在下载两个问题后,您的应用程序存储了56.5 MB。要检查您的应用程序存储了多少数据: - 转到设置> iCloud。> 存储和备份> 管理贮存 ”。我想知道如果信息没有存储在 iClound 上怎么写。

我的脚本:

- (void) DownloadFile:(NSURL *)url Name:(NSString *)name Folder:(NSString *)folder{

    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSData *myData = [NSData dataWithContentsOfURL:url];
    NSString *file = [NSString stringWithFormat:@"%@/%@",folder,name];

    if(![fileManger fileExistsAtPath:file]){
        [fileManger createFileAtPath:file contents:myData attributes:nil];
    }
}

【问题讨论】:

    标签: xcode download icloud


    【解决方案1】:

    只需将 PDF 存储在应用程序文档目录中即可。您仍然可以使用 iCloud 的键值存储来跟踪哪些文件已下载到哪些设备上。但是,要下载到设备上的文件必须来自非 iCloud 服务器。

    您可能还必须实现一个 UI,以显示哪些文件已下载,哪些文件可用,并在需要时从设备中删除它们。

    【讨论】:

    【解决方案2】:

    哦,谢谢你完成了

    #import <sys/xattr.h>
    ....
    
    -(BOOL) addSkipBackupAttributeToItemAtURL:(NSURL *)URL{
         if(&NSURLIsExcludeFromBackupKey == nil){
             const char* filePath = [[URL path] fileSystemRepresentation];
             const char* attrName = "com.apple.MobileBackup";
             u_int8_t attrValue = 1;
             int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
             return result == 0;
         }else{
             return [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];
         }
    } 
    
    - (void) DownloadFile:(NSURL *)url Name:(NSString *)name Folder:(NSString *)folder{
    
        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSURL *curfile = [NSURL fileURLWithPath:folder];
        [self addSkipBackupAttributeToItemAtURL:curfile];
        NSData *myData = [NSData dataWithContentsOfURL:url];
        NSString *file = [NSString stringWithFormat:@"%@/%@",folder,name];
    
        if(![fileManger fileExistsAtPath:file]){
            [fileManger createFileAtPath:file contents:myData attributes:nil];
        }
    }
    

    谢谢

    【讨论】:

      猜你喜欢
      • 2015-04-12
      • 2012-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-24
      相关资源
      最近更新 更多