App Storeの審査経過報告[iCloud対応] 2

前回の記事でRejectされたアプリが、本日審査を通過し、iTunesからダウンロードできる様になりました。最寄りのカフェを地図表示する「カフェしるべ」というアプリです。よろしければ、ダウロードして下さい。
http://itunes.apple.com/jp/app/id510897503

さて今回の記事の本題は、前回の記事の続きとして、Rejectされたアプリに対して行った修正についてです。

結論から言うと、前回記事で紹介した、iOS Storage Data Guidelinesの「2.ダウンロード可能なデータは、/Library/Cachesに置け」を採用しました。

問題になっていたファイルは、アプリで使用するデータを格納したSQLiteのDBファイル(約2MB)でした。このファイルがアプリインストール時に、iCloudへのバックアップ対象である「/Documents」に格納されていることが、Rejectの原因でした。

/Documents」に格納することは、意図して行ったわけではなく、Xcode上で「Resources」Groupを作成し、その中にSQLiteのDBファイルを格納しておくと、デフォルトで格納されてしまう様です。

そこで、対応策として、AppDelegateクラスに下記の処理を追加することで、SQLiteのDBファイルを「/Documents」から「/Library/Caches」に移動する手法を実施しました。

@implementation AppDelegate

//中略

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    //前略

    //「<Application_Home>/Documents」に配置されているDBファイルのファイルパスを生成
    NSArray *docPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *docDir = [docPaths objectAtIndex:0];
    NSString *docDbPath = [docDir stringByAppendingPathComponent:@"DBファイル名"];
    
    //ファイルマネージャ初期化
    NSFileManager *fm = [NSFileManager defaultManager];
    
    //DBファイルの存在確認(存在しない場合はファイル移動実施済みと判断)
    if(![fm isExecutableFileAtPath:docDbPath]){
    
        //コピー先「<Application_Home>/Library/Caches」のファイルパスを生成
        NSArray *cachesPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
        NSString *cachesDir = [cachesPaths objectAtIndex:0];
        NSString *cachesDbPath = [cachesDir stringByAppendingPathComponent:@"DBファイル名"];
        
        NSError *error;
    
        //コピー先のフォルダがない場合は作成する
        if(![fm fileExistsAtPath:cachesDir]){
        
            [fm createDirectoryAtPath:cachesDir withIntermediateDirectories:YES attributes:nil error:&error];
        }
        
        //ファイルの移動実施
        [fm moveItemAtPath:docDbPath toPath:cachesDbPath error:&error];
    
    }

    //後略

}

//中略

@end

執筆者:中の人A