【问题标题】:iOS PhoneGap app rejected because of the use of localStorageiOS PhoneGap 应用因使用 localStorage 而被拒绝
【发布时间】:2012-08-30 04:59:31
【问题描述】:

Apple 刚刚拒绝了我提交的一个 PhoneGap 应用程序。我在应用中使用 HTML5 localStorage 来保存下载的数据以进行缓存:2.23 应用必须遵循 iOS 数据存储指南,否则将被拒绝

我很困惑,因为如果我认为 5.1 中的 localStorage 实际上将数据保存在缓存中,而不是保存在 iCloud [source] 备份的地方。这是我想要的行为 - 我不需要也不希望备份数据。

我错了还是苹果错了?我可以在 PhoneGap 应用程序中做些什么来保存这些缓存数据而不会违反?

编辑:PhoneGap 1.8.1 如果有帮助的话。

【问题讨论】:

  • 我建议您使用 Xcode 下载应用程序沙箱的快照,以查看正在创建的文件和目录。也许 PhoneGap 正在做一些时髦的事情。您也可以只查看应用程序的 Simulator 目录。
  • 并确保显示隐藏文件,因为许多缓存/实现详细目录是隐藏的(例如:Core Data 外部资源存储)。
  • 如果我查看模拟器目录,它会在“Caches”目录(Applications/app/Library/Caches)中显示一个文件__0.localstorage。所以这再次证实了我认为它被保存在“正确”的地方。

标签: ios cordova local-storage


【解决方案1】:

事实证明我是对的,而苹果是错的。我确认我将所有内容都正确存储在 /Caches 目录中。他们没有对我的问题发表评论 - 只是批准了我的应用。

【讨论】:

  • 如果您只使用 localStorage,您应该向审阅者指出这一点(和/或将他们发送到此线程!)
【解决方案2】:

我知道两件事:

1) 由您的应用程序生成的文件(而不是用户使用您的应用程序的结果),例如用于存储变量值的临时文本文件,那么这些文件必须放在 Library/Cache 而不是 Document目录。

2) 您还必须使用“skip-backup”属性标记文件,以告诉 iCloud 不要备份该文件。

我认为您可能错过了第 2 步。

我编写了一个简单的 MediaDirectory 类,它可以快速为我提供库/缓存文件夹中文件的路径,并添加跳过备份属性。

将文件保存到 Libary/Cache 文件夹后,您只需执行以下操作:

[MediaDirectory addSkipBackupAttributeForFile:@"myTextFile.txt"];

这是完整的课程:

// Header File

// ----------------------------------------------------------------------
// This class takes a file name (including extension) and returns
// the path to that file in the Library/Cache folder
// ----------------------------------------------------------------------

#import <Foundation/Foundation.h>

@interface MediaDirectory : NSObject

+(NSString *) mediaPathForFileName:(NSString *) fileName;
+(NSString *) mediaPathForFileName:(NSString *) fileName inSubDirectory:(NSString *) subDirectory;
+ (BOOL)addSkipBackupAttributeToFile:(NSString *) fileName;
+ (BOOL)addSkipBackupAttributeToFile:(NSString *) fileName inSubDirectory:(NSString *) subDirectory;

@end


// Implementation File

#import "MediaDirectory.h"
#include <sys/xattr.h>

@implementation MediaDirectory

+(NSString *) mediaPathForFileName:(NSString *) fileName
{   
    NSArray *directoryPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString *cachesDirectory = [directoryPaths objectAtIndex:0];
    NSString *filePath = [NSString stringWithFormat:@"%@/%@", cachesDirectory, fileName];

    return filePath;
}

// if an image needs to be stored in a sub folder called "images"
+(NSString *) mediaPathForFileName:(NSString *) fileName inSubDirectory:(NSString *) subDirectory
{   
    NSArray *directoryPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString *cachesDirectory = [directoryPaths objectAtIndex:0];
    NSString *filePath = [NSString stringWithFormat:@"%@/%@/%@", cachesDirectory, subDirectory, fileName];

    return filePath;
}

//+ (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
+ (BOOL)addSkipBackupAttributeToFile:(NSString *) fileName
{
    const char* filePath = [[self mediaPathForFileName:fileName] 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;
}

+ (BOOL)addSkipBackupAttributeToFile:(NSString *) fileName inSubDirectory:(NSString *) subDirectory
{
    const char* filePath = [[self mediaPathForFileName:fileName inSubDirectory:subDirectory] 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;
}

@end

【讨论】:

    【解决方案3】:

    我刚刚提交的一个phonegap应用也因为同样的原因被苹果拒绝了,我只使用了localstorage。

    我已重新提交,并在我的 config.xml 中设置了以下首选项

    <preference name="BackupWebStorage" value="none" />
    

    我知道这将解决问题

    【讨论】:

      猜你喜欢
      • 2012-11-07
      • 2017-02-04
      • 1970-01-01
      • 2018-01-25
      • 1970-01-01
      • 2016-12-06
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      相关资源
      最近更新 更多