name: portada class: portada-slide, center, middle # Realm - Sync .footnote[Mateu Yábar Valles] --- --- # Configuració Atlas - Anar a App services - Selecciona template crear una realtime-sync. - Quan posi "Get the Front-End code for your Template via CLI", tanca el popup. - Ves a device-sync al menú de l'esquerre. - A "Define Permissions" pots indicar quines dades podrà legir/escriure cada usuari. --- # Configuració App ``` val realmApp = App.create("MY-App-Id") ``` ``` val realmApp = App.create(AppConfiguration.Builder("MY-App-Id") .log(LogLevel.ALL) .build()) ``` --- # Registre usuari ``` realmApp.emailPasswordAuth.registerUser(username, password) ``` --- # Login usuari ``` val creds = Credentials.emailPassword(username, password) realmApp.login(creds) val user = realmApp.currentUser!! ``` --- # Configuració ``` val config = SyncConfiguration.Builder(user, setOf(Item::class)) .initialSubscriptions { realm -> add( realm.query
(), "All Items" ) // add( // realm.query
("owner_id == $0", realmApp.currentUser!!.id), // "User's Items" // ) } .waitForInitialRemoteData() .build() println("Realm Path: ${config.path}") val realm = Realm.open(config) realm.subscriptions.waitForSynchronization() ``` --- # Insert ``` realm.writeBlocking { val item = Item(ownerId = user.id, summary = "Some summary ${Date()}") copyToRealm(item) } ```