realm / realm-swift

Realm is a mobile database: a replacement for Core Data & SQLite
https://realm.io
Apache License 2.0
16.32k stars 2.15k forks source link

realm init fail #4791

Closed l-h-d closed 7 years ago

l-h-d commented 7 years ago

I get realm instance for this method

- (RLMRealm *)currentRealm {
    if (self.currentConfiguration == nil) {
        return nil;
    }

    NSError *rlmError;
    RLMRealm *cr = [RLMRealm realmWithConfiguration:self.currentConfiguration
                                                   error:&rlmError];
    if (rlmError) {
        NSLog(@"!>>>>> \n\n-Realm Error on DB Create  :------------------------ %@: %@-----!!\n\n", self.currentConfiguration.fileURL, rlmError);
    }
    return cr;
}

-(void)initDBWithName:(NSString *)name
               UserID:(NSString *)uid
              version:(int)version {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clearEnvironmentForLogout:) name:kTNLogoutNotification object:nil];
    RLMRealmConfiguration *configuration = [[RLMRealmConfiguration alloc] init];
    NSString *libraryDirectory = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) firstObject];
    NSString* path =[NSString stringWithFormat:@"%@/Realm_v1/%@-%@.%@", libraryDirectory, name, uid, kTOONRealmDBExtension];
    NSURL* ru = [NSURL URLWithString:path];

    if (![[NSFileManager defaultManager] fileExistsAtPath:[path stringByDeletingLastPathComponent] ]) {
        [[NSFileManager defaultManager] createDirectoryAtPath:[path stringByDeletingLastPathComponent]
                                  withIntermediateDirectories:YES
                                                   attributes:nil
                                                        error:nil];
    }
    configuration.fileURL = ru;
    configuration.schemaVersion = version;

    configuration.migrationBlock = ^(RLMMigration *migration, uint64_t oldSchemaVersion) {
        [self migrateData:migration withOldVersion:oldSchemaVersion];
    };
    configuration.objectClasses = [self registerTableClasses];
    self.currentConfiguration = configuration;
}

But i go to the disk by the fileUrl, It have data。 Can you tell me that is why? Thank you !!!

pigeon-archive commented 7 years ago

Hey @l-h-d. I wanted to let you know that we've received your message and that someone will review what you've provided and be in touch with you soon. In the meantime, would you be able to share what version of Realm Cocoa you're using? Thanks.

bdash commented 7 years ago

Please also describe the behavior you're seeing. What exactly is failing? Is -[RLMRealm realmWithConfiguration:error] returning nil? If so, what error is being reported?

TimOliver commented 7 years ago

Hi @l-h-d! Just following this up. Can you please elaborate what's going on with your issue? Thanks!

jpsim commented 7 years ago

Closing due to inactivity.