caiyue1993 / icecream Goto Github PK
View Code? Open in Web Editor NEWSync Realm Database with CloudKit
License: MIT License
Sync Realm Database with CloudKit
License: MIT License
See IceCream debug logs.
No logs.
Use IceCream with Carthage.
Is this expected? I don't see any debug info and don't know if I'm doing something wrong or just the expected behavior.
Example: I index my model objects into CoreSpotlight for searching. It would be great if SyncEngine
had a postUpdate
block in which I could do additional work on the updated model. Maybe like
class SyncEngine {
…
var postUpdate: ((added: [T], deleted: [T], updated: [T]) -> ()) = { _, _, _ in }
…
and then invoke it in fetchChangesInZone
after all the changesOp
blocks complete. Or if it would make it easier, one block per each: postAdd
, postUpdate
, postDelete
.
I'm happy to do this in a pull request if it seems like a good direction.
In the Usage part of the README.md, a section should be added regarding remote notifications.
Otherwise, by default, no remote notifications will be synchronised by the SyncEngine.
The code presents in the Example could be a good start :
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
let dict = userInfo as! [String: NSObject]
let notification = CKNotification(fromRemoteNotificationDictionary: dict)
if (notification.subscriptionID == IceCreamConstant.cloudKitSubscriptionID) {
NotificationCenter.default.post(name: Notifications.cloudKitDataDidChangeRemotely.name, object: nil, userInfo: userInfo)
}
completionHandler(.newData)
}
Reference to Realm Object Server, it registers the types to be synced to server once at launch.
I´ve multiple Realm objects and I expected them all to sync with Cloudkit but only some do. I just call and store reference of multiple SyncEngine references. Is that supported?
Only some syncEngines seem to work.
Does IceCream support CKAsset. I'm using CloudKit, and there are some images needs to save in iCloud. I didn't find some code about CKAsset.
Will you support it in the future if you haven't support it yet?
Hi, I'm caught a crash with error message:
*** Terminating app due to uncaught exception 'RLMException', reason: 'Invalid value '1' of type 'NSTaggedPointerString' for 'int' property 'DictionaryObj.id'.'
I have this issue because my id in all objects is Int type, I guess.
import RealmSwift
import IceCream
final class DictionaryObj: Object {
@objc dynamic var id = 0
@objc dynamic var name = ""
@objc dynamic var isIncome = false
override class func primaryKey() -> String? {
return "id"
}
//Incrementa ID
static func incrementId() -> Int {
let realm = try! Realm(configuration: CONFIG_REALM)
if let lastObj = realm.objects(DictionaryObj.self).sorted(byKeyPath: "id").last {
return lastObj.id + 1
} else {
return 1
}
}
}
extension DictionaryObj: CKRecordConvertible {
var isDeleted: Bool {
return false
}
// Yep, leave it blank!
}
extension DictionaryObj: CKRecordRecoverable {
// Leave it blank, too.
}
EDIT: I traced it to the Cream.swift file's init. This occurs when the Realm is Encrypted.
I recently incorporated IceCream into my project, and after code setup through looking at Example Project and the Docs, Xcode crashes (and the app) when syncEngine = SyncEngine<MyRealmClassHere>()
is called in AppDelegate. This only occurs when AppleID is signed in.
Details: Swift 4, Xcode 9.1 (9B55), iPhone 6 Simulator
Code execution goes as normal, no crash. SyncEngine runs.
Run project, Xcode crashes upon app start up. I have tracked it down to SyncEngine crashes Xcode and app only when AppleID is logged in, regardless of whether it can connect to any data or not (EX: wifi off).
Hi, I have one question. If I delete app, my all data deleting on iCloud too? Can I save this data on iCloud and when app reinstalling all data loading again?
Hi ,
I can't install IceCreeam using CocoaPods
I got this message :
[!] CocoaPods could not find compatible versions for pod "IceCream":
In Podfile:
IceCream (~> 1.3.0)
Specs satisfying the `IceCream (~> 1.3.0)` dependency were found, but they required a higher minimum deployment target.
However, the CKRecord.Reference class does not support cross-zone linking, so each reference object must point to a record in the same zone as the current record.
public static var customZoneID: CKRecordZone.ID {
return CKRecordZone.ID(zoneName: "\(recordType)sZone", ownerName: CKCurrentUserDefaultName)
}
IceCream create custom zone every object class, but reference can't link.
So, why not use default zone?
IceCream should sync Realm's Link format to CloudKit's Arrays.
IceCream completely ignores Realm's Links.
Could IceCream be updated to support Links? (only with the types of Arrays CloudKit supports are needed).
Hi,
I was looking for a way to sync my Realm database with CloudKit, and IceCream seems to be the best solution for it. However, I'm using references in my Realm database and IceCream doesn't seem to support those yet. Would it be a viable workaround to save the ID of an object instead of the object reference?
Thank you,
Stefan
Please can a switch be implemented so that we can choose to synchronise private or public iClod databases?
Support minimum deployment target iOS 10.0
The minimum deployment target is iOS 11.2 right now
I have a cartfile with contents as github "caiyue1993/IceCream".
The carthage log file contains the error:
error: no such file or directory: '/Users/xxxxx/Carthage/Checkouts/IceCream/IceCream/Classes/SyncSource.swift'
On running carthage update..here is the full terminal output:
*** Cloning IceCream
*** Cloning realm-cocoa
*** Checking out IceCream at "1.4.0"
*** Downloading realm-cocoa.framework binary at "v3.5.0"
*** Skipped installing realm-cocoa.framework binary due to the error:
"Incompatible Swift version - framework was built with 4.1 (swiftlang-902.0.48 clang-902.0.37.1) and the local version is 4.0 (swiftlang-900.0.65 clang-900.0.37)."
*** Checking out realm-cocoa at "v3.5.0"
*** xcodebuild output can be found in /var/folders/7f/y0vvrb7563n6m_2_g8ck9_3r0000gp/T/carthage-xcodebuild.kAk0wC.log
*** Building scheme "RealmSwift" in Realm.xcworkspace
*** Building scheme "Realm" in Realm.xcworkspace
*** Building scheme "IceCream" in IceCream.xcodeproj
Build Failed
Task failed with exit code 65:
/usr/bin/xcrun xcodebuild -project /Users/muhammadimran/Documents/Work/Apple/CODE/IslamAndQuranPro_code_bk/Carthage/Checkouts/IceCream/IceCream.xcodeproj -scheme IceCream -configuration Release -derivedDataPath /Users/muhammadimran/Library/Caches/org.carthage.CarthageKit/DerivedData/9.0_9A235/IceCream/1.4.0 -sdk iphoneos ONLY_ACTIVE_ARCH=NO BITCODE_GENERATION_MODE=bitcode CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES archive -archivePath ./ GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=NO CLANG_ENABLE_CODE_COVERAGE=NO (launched in /Users/muhammadimran/Documents/Work/Apple/CODE/IslamAndQuranPro_code_bk/Carthage/Checkouts/IceCream)
This usually indicates that project itself failed to compile. Please check the xcodebuild log for more details: /var/folders/7f/y0vvrb7563n6m_2_g8ck9_3r0000gp/T/carthage-xcodebuild.kAk0wC.log
I can define which realm should be synced.
Right now, the default realm is used, sometimes with Cream, sometimes not. (as far as I saw)
I noted it because of migration issues. So as described in Realm Documentation you can change the Realm-config for local migrations.
I would love to give the realm I set up as a parameter to the SyncEngine.
I can provide a small fix if you want.
It would be great to be able to install this via Carthage as well as CocoaPods!
When application launches for first time, it needs time to synchronize data, but I can not find in readme or example any callback to know whether app is synchronizing or finish. Is there anyway to detect those events?
Does this library handle two-way sync? Let's say we have one record per day (tracking user steps taken every day), user's data is synced for 10 days, the user deletes the app and installs again, the previous 10 days data will be available locally after the sync?
I create the object with specific properties (in my app example Habit with habit infos) and additional objects referencing to this object (one-to-many) - statuses for specific dates related to habit. Initial sync seems to be working well, because data gets stored and is visible on iCloud dashboard.
Up to this point, data is synced but if I remove the application and install in on device again, some of the items are missing, even tho they are stored in iCloud. Same goes if I install the app on other device.
First I create the habit and change status to success on certain dates (simulator):
I install the app on my real device, open the calendar and statuses on speicfic dates are missing (18):
As you can see on my dashboard, there are 7 records and 18th day is there as well..
Even futher, if I add more statuses and reinstall the app then even more of them are missing.
Example with more statuses going away:
Seems like I am having some problems with syncing. @caiyue1993, any idea? If you need more information about code, let me know.
Hey guys, this library is awesome thank you for creating it.
I've noticed that when launching the SyncEngine the first time it syncs, I get the following errors:
"ErrorHandler.Fail: Zone Not Found: the specified record zone does not exist on the server.CKError.Code: 26"
.
I checked the code and I noticed that in the init, the createCustomZones
function is called after syncRecordsToCloudKit
, so I believe this is why I get the errors.
The flow I use in the app is the following:
iCloud is disabled by default, the user can add objects to realm and use the app.
In Settings I've a toggle to turn iCloud on, when that happens the SyncEngine gets initialized.
At the moment as a workaround I just call syncRecordsToCloudKit
after the init and that solves the problem.
Thank you.
CloudKit now has the sharing feature. It would be cool if we could have a way to sync records using the shared database as well (and maybe an easy way to create shares using IceCream)
When preparing an app that depends on IceCream (via Carthage) for the Store/Testflight the following errors are given: ...contains disallowed nested bundles
and ...contains disallowed file 'Frameworks'
.
The project itself depends on realm-cocoa
as well, so in addition, I get CFBundleIdentifier Collision. There is more than one bundle with the CFBundleIdentifier value…
for Realm
and RealmSwift
.
It is my understanding this is due to the copy framework script. While this seems to work during runtime (and on my device), it causes submission problems. So the copy framework phase should probably be removed and only happen at the app level.
Similar discussions I found regarding this issue:
My app gives the user the option to delete all his data and also to restore data from backup files.
When erasing all data, I used realm.deleteAll()
. Now that I'm using IceCream, I iterate over all my objects and set isDeleted
to true
.
Then, when restoring data, I go over a different Realm database and use realm.create()
to add it to the current Realm.
Now, using IceCream, if I open my app in two devices at the same time, erase all data and then add it back from a backup file, the app will receive the cloudKitDataDidChangeRemotely
hundreds of times and it'll hang forever, making it unusable and requiring me to force quit.
In these cases I think it would be better to group multiple changes together and sync them on a background thread.
Is what's shown on the read me the only required setup?
What if we have more than one realm object (EX: dog and human classes)
Compile without errors
tried to pod reintegrate, and clean derived data and Xcode project
compiles with errors indicating that methods
syncObjects
errorHandler
privateDatabase
fetchChangesInDatabase
notificationToken
are inaccessible due to private protection level in file SyncEngine
Add IceCream 1.5.0 to Podfile, pod install
, compile project.
OR
git clone
library GitHub repo, pod install
in Example folder, compile project
pod try
works without any problems.
Hi ,
I have 2 Realm lists
I tried to use this library
but no luck in make it working
Currently, IceCream is print
ing a lot of information to the console. Most of the time, I don't need as much information (like every database item). The many logs sometimes even get in the way of development, as I have trouble finding my own debug log outputs.
I would love it if logging could be optional. This could be achieved either through delegation, where the delegate functions receives information about the sync status or errors, which I can then print if I want to. The other way (I think) would be through completion handlers / closure blocks that provide information, that I can also decide on whether to print or not.
Is this something useful or needed, or is there some other way to turn off logs from a framework?
Thank you for your great work!
I'm try to extension my already exists realm object with IceCream's CKRecordConvertible & CKRecordRecoverable, And may I wonder does IceCream support CKReference & Realm's LinkingObjects?
For example:
I have a realm object like this:
class HistoryRecord: Object {
@objc dynamic var ckRecordID = NSUUID().uuidString
@objc dynamic var isDeleted = false
@objc dynamic var updateTime: TimeInterval = Date().timeIntervalSince1970
@objc dynamic var linkedDigest: LocalDigest?
}
I used to save the "LinkedDigest" as a CKReference in CloudKit.
And how about the Realm's LinkingObjects?
It shouldn't be too hard to add support to macOS, tvOS and watchOS
I'm building an app, that should backup local realm updates with icloud. So when I run first install, there are some objects from backed realm appear, but I want to do some operations with new objects.
How can I receive any info, about new objects, so I can do some operations with them?
I know the CoreData supported the incremental update, and realm file do not support it. Does the IceCream automatically detect the change of the realm database and upload the file to the iCloud?
How could I start or stop IceCream to sync with icloud?
I had deleted IceCream
from my project
and I'm sure the pre-bundle Realm file doesn't have CreamAsset
but after I run the app
I found there is CreamAsset in my realm file
how that is possible ?
and how can I delete it ?
When adding a new field to the Realm model, the CloudKit records that exist, do not update to have that field also.
This causes sync to fail and not load over people's devices.
Since updating to latest IceCream (from 1.6.x to 1.7.x) I am no longer seeing debug statements. I tried running the Example app inside the repo and also don't see IceCream debug printouts. I am using Carthage and did not modify the source. Were these removed?
IceCream outputs debug log statements to the console
No debug statements are printed
IceCream works with the latest version of Swift!
IceCream works with Swift 4.0, but not Swift 4.2. These errors occur:
Create a new project with Xcode 10 or later, add IceCream as a dependency using CocoaPods, then build.
I can have a PR ready, if desired!
Below is the issue template. You can fill each part then submit your issue.
Or you can just delete all of these and describe your questions in you-like style.
But please remember: the more detailed info you offered, the greater possibility your problem will be solved. 😜
// Please replace this line with your expected behavior.
// Please replace this line with the actual behavior.
// Please provided to steps to reproduce the problem
// Please offer the reference links to us. We appreciate it.
CloudKit recommends to track local changes for offline work.
Sync existing realm data to CloudKit.
Objects present in the database before adding Icecream doesn´t sync.
Create a realm database without Icecream, add and setup Icrecream to your project. Only updates are pushed to the cloud.
Hi,
What's the purpose of appending an UUID to the uniqueFileName property ?
self.uniqueFileName = "\(uniqueKey)_\(UUID().uuidString)"
The use-case i'm facing is the update of an image asset for the same object (i.e same unique key).
From the API, i suppose the proper way of updating an asset is by recreating a CreamAsset object. In this case, the uniqueFileName property will be a new unique one, and the 2 images will be stored on the userDevice.
Am i missing something ?
It would be cool if this could leverage Codable
or some other mechanism so we didn't have to manually serialize/deserialize the records.
IceCream does not split CloudKit requests into smaller chunks in syncObjectsToCloudKit
. This can lead errors such as the following:
Error: Your request contains 492 items which is more than the maximum number of items in a single request (400)
Realm collection notifications can easily contain many items (e.g. due to realm/realm-swift#3494 or during a bulk import). Most of the times, it can be worked around on the application level, but I think the library should handle this case gracefully.
All modified objects are updated in CloudKit.
The CloudKit request fails with the error above.
Hey!
First of all, thank you for such a great option to have! Yesterday I was playing with Realm + Realm Platform but then I found out about IceCream and it works like charm.
My question is, could it be possible for user to select either he wants to sync to iCloud or just store locally?
My app is storing record data and I am not sure how Apple is with the way that IceCream automatically syncs to signed Apple account? I would love to have an option i.e. on onboarding part for user to select if he wants to enable sync or not. Is that possible? How are you dealing with this?
Edit: Additional question. If I install app on my device, it works like charm. If I put it on Testflight, friend doesn't get data synced back after reinstall. Is it because I am using Development container and I should deploy to Production?
Thanks,
Zan
Related link: Many-to-many relationship in Realm
#68 provided a way of implementing this feature but it's not that neat. It has used a internal class(ListBase
) of Realm which is not recommended. So this issue is trying to collect a better way of implementing this feature.
I'm considering leveraging IceCream for a personal project I'm working on currently. I'm concerned with how IceCream handles realm data model migrations.
Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.