I am trying to sync Realm in my application with iCloud / CloudKit, but without success ...
Here is my source code:
-(void)sync { NSURL *baseURL = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil]; if (baseURL) //iCloud is active { NSURL *serverURL = [NSURL URLWithString:@"http://myMacBookNwtworkIP:9080"]; //Realm Object Server is up and running at this URL RLMSyncCredential *usernameCredential = [RLMSyncCredential credentialWithUsername:@"myUsername" password:@"myPassword" actions:RLMAuthenticationActionsUseExistingAccount]; RLMSyncCredential *iCloudCredential = [RLMSyncCredential credentialWithICloudToken:@"myiCloudToken"]; [RLMSyncUser authenticateWithCredential:usernameCredential authServerURL:serverURL onCompletion:^(RLMSyncUser *user, NSError *error) { if (user) { //user recognized in my real object server // can now open a synchronized RLMRealm with this user RLMRealmConfiguration *config = [RLMRealmConfiguration defaultConfiguration]; /* CRASH AT THIS LINE! */ config.syncConfiguration = [[RLMSyncConfiguration alloc] initWithUser:user realmURL:serverURL]; RLMRealm *realm = [RLMRealm realmWithConfiguration:config error:nil];// Any changes made to this Realm will be synced across all devices! } else if (error) { // handle error NSLog(@"error %@",error); } }]; } }
When I try to execute exec
config.syncConfiguration = [[RLMSyncConfiguration alloc] initWithUser:user realmURL:serverURL];
I get this error
The URL provided ( http: // myMacBookNwtworkIP: 9080 ) is not a valid Realm URL.
How can I solve it?
Also, since this is my first attempt to save something in iCloud, how do I use iCloudCredential ? In fact, if I replaced usernameCredential with it, then user always nil ...
I followed these steps on these links:
source share