[英]Can't sync Realm with iCloud
我正在嘗試將我的應用中的Realm與iCloud / CloudKit同步,但沒有成功......
這是我的源代碼:
-(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];
我收到這個錯誤
提供的URL( http:// myMacBookNwtworkIP:9080 )不是有效的域URL。
我該如何解決?
另外,由於這是我第一次嘗試在iCloud中保存一些內容,我應該如何使用iCloudCredential
? 事實上,如果我用它替換usernameCredential
,那么user
總是沒有...
我按照這些鏈接的步驟:
為了防止崩潰,有必要指定“領域”協議而不是“http”,如下所示
config.syncConfiguration = [[RLMSyncConfiguration alloc] initWithUser:user realmURL:[NSURL URLWithString:@"realm://myMacBookNwtworkIP:9080"]];
感謝這個鏈接
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.