2016-05-29 11 views
0

私の英語のために申し訳ありません。私はストレージに問題があり、Appleは私のアプリケーションを拒否しました。私はdb内の更新レコードが必要なので、私のアプリでsqlite dbを使用し、バンドルからコピーします。これについては多くの情報がありますが、私にとってはうまく機能しません。IOSストレージの問題

私はディレクトリNSApplicationSupportDirectorylibrary/caches別でNSURLIsExcludedFromBackupKeyを使用するようにしようと試みたが、それは働いていないと私は私のDBをコピーしない場合、私はストレージに私のアプリを参照してくださいいけないが、私は必要、DBのサイズのストレージに私のアプリを見ますコピー。

私は何をしなければなりませんか?

私は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

を、iOSのデータに準拠していない起動し、コンテンツのダウンロードには – Idali

+0

2.23詳細、アプリストア、ユーザーのiCloudの上の66.91メガバイトを、アップルの拒否の説明を追加してください –

+0

と私はまた、この67 MBのストレージを参照してください、なぜ私は何か考えがありますか? –

答えて

1

を「ユーザーがデータを生成」が、昼食のアプリケーションで、Appleは「ない知りたいですこのダウンロードしたデータに適用するためのバックアップポリシー(iCloud)と、このデータを再作成できるかどうかを確認します。 /またはストレージが少ない状況であってもデバイスに残る必要があります。すべてのこのような状況はよくですから、アプリ-発射ダウンロード・データのための政策は、あなたの問題を解決します提供iOS Data Storage Guidelines

を説明してい...

あなたのケースでは、あなたはそうappDelegateで、applicationSupportDirectoryのみskipBackupする必要があるかもしれませんdidFinishLaunchingWithOptionsはバックアップをスキップ追加:

//[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について、私は今ではApple以外のものすべてを使っていません。アプリケーション - 設定> iCloud>ストレージ>ストレージの管理 - デバイスを選択 - 必要に応じて「すべてのアプリケーションを表示」をタップ - アプリのストレージを確認します。この場合、67mbが表示されます( –

+0

あなたのbasePathの正しいパスをapplicationSupportDirectory – Idali

+0

助けてくれてありがとう、私は間違ったメニューを見たことがありますが、icloudではなく、私の電話でこの方法でロシア語だったので解決済みの問題を解決しようとしました) ロシア語インターフェースthis "Go to設定> iClo ud>ストレージ>ストレージを管理する - デバイスを選択してください "正しいパスではないとローカルストレージへのパスのように見えますが、私は67メガバイトを見ましたが、icloudでは67でした!これは私がフォーラムでこの質問を見た別の質問ですリンゴのサイズは、人が見るよりも違っていますが、今それは私の問題ではない、私の問題は解決されています –