2016-11-11 7 views
5

私はiCloud上/ CloudKitと私のアプリでレルムを同期しようとしているとレルムを同期することはできませんが、成功せず...ここ はiCloudの

は、それは私のソースコードです:

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

私は

config.syncConfiguration = [[RLMSyncConfiguration alloc] initWithUser:user realmURL:serverURL]; 

をexecししようとすると、私はこのエラー

提供されたURL(0123を取得します)は有効なレルムURLではありませんでした。

どうすれば解決できますか?

また、iCloudで何かを保存しようとするので、iCloudCredentialはどうすればいいですか?クラッシュを防ぐために

  1. https://realm.io/docs/objc/latest/#the-realm-mobile-platform
  2. https://realm.io/docs/realm-object-server/#authentication

答えて

3

:実際には、私はそれでusernameCredentialを置き換える場合は、userは常にnilです...

私はこれらのリンクの手順に従っ「http」の代わりに「

」のように 「領域」プロトコルを指定する必要があります
config.syncConfiguration = [[RLMSyncConfiguration alloc] initWithUser:user realmURL:[NSURL URLWithString:@"realm://myMacBookNwtworkIP:9080"]]; 

ありがとうございましたthis link

関連する問題