2016-05-29 56 views
0

對不起,我的英語。我有一個存儲問題,Apple拒絕了我的應用程序。我在我的應用程序中使用了一個sqlite數據庫,並從數據包中複製它,因爲我需要數據庫中的更新記錄。有很多關於這方面的信息,但它不適合我!IOS存儲問題

我tryed使用NSURLIsExcludedFromBackupKey使用目錄NSApplicationSupportDirectorylibrary/caches和另一個,但它不工作,我看到我的存儲應用程序與數據庫的大小,如果我不能複製我的分貝我沒有看到我在存儲應用程序,但我需要複印件。

我該怎麼辦?

我用iOs9,Xcode中7:

BOOL success; 
NSFileManager *fileManager = [NSFileManager defaultManager]; 
NSError *error; 
stringByAppendingPathComponent:@"db_words"]; 
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] 
stringByAppendingPathComponent:@"db_words"]; 
NSURL *applicationSupportDirectory = [[NSFileManager defaultManager]  URLForDirectory:NSApplicationSupportDirectory 
                    inDomain:NSUserDomainMask 
                    appropriateForURL:nil 
                     create:YES 
                     error:&error]; 

NSURL *referenceFolder = [applicationSupportDirectory  URLByAppendingPathComponent:@"Reference" isDirectory:YES]; 

success = [[NSFileManager defaultManager] createDirectoryAtPath:[referenceFolder path] 
           withIntermediateDirectories:YES 
               attributes:nil 
                error:&error] 

success = [referenceFolder setResourceValue:@YES forKey: NSURLIsExcludedFromBackupKey error: &error]; 

if(!success){ 
    NSLog(@"KCDM: Error excluding %@ from backup %@", referenceFolder, error); 
} 


NSString * writableDBPath = [referenceFolder.path stringByAppendingPathComponent:@"db_words"]; 
success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error]; 
if (!success) 
    NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]); 

return writableDBPath; 
+0

請用戶的icloud的,這不符合iOS的數據添加蘋果公司拒絕說明, – Idali

+0

2.23詳細信息發佈和下載內容,您的應用程序商店66.91 MB –

+0

,我也看到這67米的存儲空間,但我沒有任何想法爲什麼? –

回答

1

由於在發射和下載內容沒有被用戶啓動的「用戶生成的數據」,但你在午餐的應用程序,蘋果想知道「不備份「政策(對iCloud)適用於此下載的數據,並且如果可以重新創建此數據? /或者應保持在設備上,即使在低存儲情況下也是如此。所有這些情況都很好,你的情況你可能只需要skipBackup爲applicationSupportDirectory解釋iOS Data Storage Guidelines

所以提供給你的應用程序 - 啓動下載的數據的策略能夠解決您的問題...

,所以在appDelegatedidFinishLaunchingWithOptions添加跳過備份:

//[self addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:[AppDelegate applicationDocumentsDirectory]]]; 

    //[self addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:[AppDelegate applicationLibraryDirectory]]]; 

    //[self addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:[AppDelegate applicationTemporaryDirectory]]]; 

    [self addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:[AppDelegate applicationSupportDirectory]]]; 

使用「不備份」屬性指定應該留在設備,即使在低存儲情況的文件。將 屬性與可重新創建的數據一起使用,但需要在 低存儲情況下仍然存在,以便您的應用正常運行,或者因爲 客戶希望在脫機使用期間可以使用該數據。

,並添加這個方法:

 - (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; 
     } 

     + (NSString *) applicationDocumentsDirectory 
     { 
      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
      NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil; 
      return basePath; 
     } 

     + (NSString *) applicationLibraryDirectory 
     { 
      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES); 
      NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil; 
      return basePath; 
     } 

     + (NSString *) applicationTemporaryDirectory 
     { 
      return NSTemporaryDirectory(); 
     } 




     + (NSString *) applicationSupportDirectory //review this to get the right basePath 
    { 
    // return basePath to applicationSupportDirectory 
     //NSURL *applicationSupportDirectory = [[NSFileManager 
    // defaultManager] 
    //URLForDirectory:NSApplicationSupportDirectory 
    // inDomain:NSUserDomainMask appropriateForURL:nil create:YES 
    // error:&error]; 

    //OR use 
    // NSString *appSupportDir = 
    //[NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, 
    // NSUserDomainMask, YES) lastObject]; 
    //appSupportDir = [appSupportDir 
    // stringByAppendingPathComponent:@"MyAppDirectory"]; 
    //return [NSURL URLWithString:appSupportDir]; 
    } 
+0

關於iCloud,我現在不是全部,但它來自蘋果「要檢查您的應用程序存儲了多少數據: - 安裝並啓動您的應用程序 - 轉到設置> iCloud>存儲>管理存儲 - 選擇您的設備 - 如有必要,點擊「顯示所有應用程序」 - 檢查您的應用程序的存儲空間「,在這種情況下,我看到67MB( –

+0

一定要獲得正確的路徑到您的basePath到applicationSupport目錄 – Idali

+0

感謝您的幫助,我認爲我看到錯誤的菜單,而不是icloud,因爲它是在我的手機在俄羅斯,並以這種方式,我試圖解決解決問題) 在俄羅斯接口這個「去設置> iClo存儲>管理存儲 - 選擇你的設備「不正確的路徑,它似乎是一個本地存儲路徑,我看到我的67 MB,但在icloud從來沒有67!這是另一個問題,我看到這個問題在論壇上蘋果寫的大小不同,比人們看到,但現在它並不重要,我的問題已解決 –