7

この問題のために私のアプリケーションは拒否されました:

http://i.imgur.com/yajQh.png

私のアプリケーションは、ブックマークなどを使用してSQLDBを使用する辞書です...

だから私はappDelegate.mのAppleドキュメントからこのコードをコピーしました:

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

しかし、このように使用されます:

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

    [self addSkipBackupAttributeToItemAtURL:[NSURL URLWithString:@"<myApplication>/Library/Caches"]];
}

しかし、この理由でクラッシュします:

アサーションに失敗しました:([[NSFileManager defaultManager] fileExistsAtPath:[URL path]])、function-[AppDelegate addSkipBackupAttributeToItemAtURL:]、file /iData/Development 2011 / My iPhone Project / APPNAME / APPNAME / AppDelegate.m、27行目。

その写真によると、これは私の拒絶の唯一の問題ですか?データベースを扱うのはこれが初めてだからです。

ありがとう 。~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

編集済み:

- (NSString *) getDBPath
{
    NSInteger kValue = [[[NSUserDefaults standardUserDefaults] stringForKey:@"Bv"] intValue];

    NSString *documentsDir = [[NSString alloc] init];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
    documentsDir = [paths objectAtIndex:0];


    switch (kValue) {

            case 0:
            documentsDir = [NSString stringWithFormat:@"%@/eng-per.sqlite", documentsDir];
            break;
        case 1:
            documentsDir = [NSString stringWithFormat:@"%@/eng-per.sqlite", documentsDir];
            break;

        case 2:
            documentsDir = [NSString stringWithFormat:@"%@/per-eng.sqlite", documentsDir];
            break;
}

return documentsDir

}

次に、アプリデリゲートでこれに変更しました。m:

[self addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:dbClass.getDBPath]];

アプリがクラッシュすることなく正常にランチするようになりました

4

1 に答える 1

4

オンラインでそのアサートをヒットしているため、アプリは「クラッシュ」しています。

assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);

そして、私はあなたの問題が実際にあなたがURLを設定している方法にあると思います:

[NSURL URLWithString:@"<myApplication>/Library/Caches"];

どのようにして「<myApplication>」への道を歩んでいますか?

アプリケーションの真のキャッシュフォルダを取得する必要があります。これは、次の方法で実行できます。

[NSFileManager defaultManager] URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask];(ファイルURLを介して返される場所の場合)

また

NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);(NSString形式のパスの場合)

したがって、最終的には、キーがすでにデフォルトで設定されている場合はアサート せず、保存するファイルのファイルURLを適切に設定する必要があります。

次のようなものを使用して、URL(正確にはファイルURL)を作成します。

NSArray * arrayOfURLs = [[NSFileManager defaultManager] URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask];
// make certain there's at least one file url returned by the above call
if([arrayOfURLs count] > 0)
{
    // and this would just be the URL to the cache directory...
    NSURL * cacheDirectoryPath = [arrayOfURLs objectAtIndex: 0];

    // ... to create a file url to your actual dictionary, you'd need to add a
    // filename or path component.

    // Assuming you save this as a property within your object
    self.cacheFileURL = [cacheDirectoryPath URLByAppendingPathComponent: @"myDatabase.db"];
}
于 2012-11-21T17:38:08.250 に答える