ddb*_*ddb 5 objective-c realm ios icloud cloudkit
我正在尝试将我的应用中的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);
}
}];
}
}
Run Code Online (Sandbox Code Playgroud)
当我试图执行
config.syncConfiguration = [[RLMSyncConfiguration alloc] initWithUser:user realmURL:serverURL];
Run Code Online (Sandbox Code Playgroud)
我收到这个错误
提供的URL(http:// myMacBookNwtworkIP:9080)不是有效的域URL.
我该如何解决?
另外,由于这是我第一次尝试在iCloud中保存一些东西,我该如何使用iCloudCredential?事实上,如果我usernameCredential用它替换,那么user总是没有...
我按照这些链接的步骤:
为了防止崩溃,需要指定“realm”协议而不是“http”,如下所示
config.syncConfiguration = [[RLMSyncConfiguration alloc] initWithUser:user realmURL:[NSURL URLWithString:@"realm://myMacBookNwtworkIP:9080"]];
Run Code Online (Sandbox Code Playgroud)
感谢这个链接
| 归档时间: |
|
| 查看次数: |
770 次 |
| 最近记录: |