2012-09-05 44 views
14

Apple剛剛拒絕了我提交的PhoneGap應用。我在應用程序中利用HTML5 localStorage來保存下載數據以實現緩存目的:2.23應用程序必須遵循iOS數據存儲指南,否則它們將被拒絕iOS PhoneGap應用因使用localStorage而被拒絕

我很困惑,因爲如果有什麼我認爲5.1中的localStorage實際上將數據保存在緩存中,而不是在用iCloud [source]備份的地方。這是我想要的行爲 - 我不需要或希望數據被備份。

我錯了還是蘋果?我可以在PhoneGap應用程序中執行哪些操作來保存這些緩存數據而不違反?

編輯: PhoneGap 1.8.1如果有幫助。

+2

我會建議你使用Xcode中下載應用程式的沙箱中的快照採取看看哪些文件和目錄正在創建。也許PhoneGap正在做一些有趣的事情。你也可以看看應用程序的Simulator目錄。 –

+0

並確保顯示隱藏的文件,因爲許多緩存/實現細節目錄是隱藏的(例如:核心數據外部資源存儲)。 –

+0

如果我查看模擬器目錄,它會在「Caches」目錄(Applications/app/Library/Caches)中顯示一個file__0.localstorage。所以這再一次證明了我的想法,即它被保存在「正確的」地方。 –

回答

11

事實證明我是正確的,蘋果是錯的。我確認我正確地將所有內容存儲在/ Caches目錄中。他們沒有評論我的問題 - 只是批准了我的應用程序。

+0

相同的拒絕。 Iphone也拒絕我的應用程序。我能做什麼 ??? – chhameed

+1

如果您只使用localStorage,您應該向評論者指出(和/或將它們發送給此主題!) –

2

有兩件事情,我所知道的:

1)由您的應用程序生成的文件(並使用你的應用程序的用戶)如臨時文本文件來存儲變量的值不是一個結果,那麼這些文件必須放置在庫/緩存中而不是文檔目錄中。

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 
1

我剛剛提交的phonegap應用程序由於相同的原因已被Apple拒絕,我只使用localstorage。

我已重新提交具有以下偏好我的config.xml中設置

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

我明白這將解決此問題

相關問題