Tôi đang cố gắng để đồng bộ hóa các Realm trong ứng dụng của tôi với iCloud/CloudKit, nhưng không thành công ...Không thể đồng bộ hóa với iCloud Realm
Ở đây nó là mã nguồn của tôi:
-(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);
}
}];
}
}
khi tôi cố gắng exec
config.syncConfiguration = [[RLMSyncConfiguration alloc] initWithUser:user realmURL:serverURL];
tôi nhận được lỗi này
Các URL được cung cấp (http://myMacBookNwtworkIP:9080) không phải là URL địa chỉ hợp lệ.
Tôi làm cách nào để giải quyết?
Ngoài ra, vì đây là lần đầu tiên tôi cố gắng lưu nội dung nào đó trong iCloud, tôi nên sử dụng số iCloudCredential
như thế nào? Trong thực tế, nếu tôi thay usernameCredential
với nó, sau đó user
luôn là con số không ...
Tôi đi theo bước tại những liên kết này:
- https://realm.io/docs/objc/latest/#the-realm-mobile-platform
- https://realm.io/docs/realm-object-server/#authentication