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);
}
}];
}
}
當我嘗試給exec
config.syncConfiguration = [[RLMSyncConfiguration alloc] initWithUser:user realmURL:serverURL];
我得到這個錯誤
所提供的網址(http://myMacBookNwtworkIP:9080)不是有效的Realm URL。
我該如何解決?
此外,由於這是我第一次嘗試在iCloud中保存某些東西,我應該如何使用iCloudCredential
?事實上,如果我用它取代usernameCredential
,然後user
永遠是零...
我跟着這些鏈接步驟:
- https://realm.io/docs/objc/latest/#the-realm-mobile-platform
- https://realm.io/docs/realm-object-server/#authentication