GithubHelp home page GithubHelp logo

caiyue1993 / icecream Goto Github PK

View Code? Open in Web Editor NEW
1.9K 1.9K 243.0 564 KB

Sync Realm Database with CloudKit

License: MIT License

Swift 98.19% Ruby 1.24% Shell 0.09% C 0.47%
cloudkit realm-database realmswift swift

icecream's People

Contributors

aplusm avatar binlogo avatar bitomule avatar bobspryn avatar bofrese avatar caiyue1993 avatar davidrothera avatar dbmrq avatar fouquet avatar ingmarstein avatar jnchman avatar jonyfang avatar julianschiavo avatar kitlangton avatar linuxsuren avatar meteochu avatar monkeywithacupcake avatar mrfufufu avatar randycarney avatar raullermen avatar revolter avatar roczhang9673 avatar ss18 avatar tiagomartinho avatar tzechuen avatar yulian948 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

icecream's Issues

Prints with Carthage

Expected behavior

See IceCream debug logs.

Actual behavior(optional)

No logs.

Steps to reproduce the problem(optional)

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.

Add pre/post hooks for model object updates

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.

README.md : Add Entry for remote notifications setup

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)
       
   }

Error with multiple objects

Expected behavior

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?

Actual behavior(optional)

Only some syncEngines seem to work.

CKAsset support

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?

'Invalid value '1' of type 'NSTaggedPointerString' for 'int'

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.
}

Encrypted realm leads to crash

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

Expected behavior

Code execution goes as normal, no crash. SyncEngine runs.

Actual behavior(optional)

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).

Steps to reproduce the problem(optional)

  1. Set up according to documentation, also looking at example project.
  2. Run SyncEngine after Realm Migration. I tried it before migration, same error.

Backup issue

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?

issue with CocoaPods !!

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.

Why create custom zone?

Document

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?

Support Realm's Link format

Expected behavior

IceCream should sync Realm's Link format to CloudKit's Arrays.

Actual behavior(optional)

IceCream completely ignores Realm's Links.

Could IceCream be updated to support Links? (only with the types of Arrays CloudKit supports are needed).

Workaround for using references?

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

Support iOS 10.0

Expected behavior

Support minimum deployment target iOS 10.0

Actual behavior(optional)

The minimum deployment target is iOS 11.2 right now

Build failed when installing using carthage update

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

Custom Local Realm

Expected behavior

I can define which realm should be synced.

Actual behavior(optional)

Right now, the default realm is used, sometimes with Cream, sometimes not. (as far as I saw)

Steps to reproduce the problem(optional)

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.

Carthage support

It would be great to be able to install this via Carthage as well as CocoaPods!

Two way Sync

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?

Reference syncing problem

Expected behavior

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.

Actual behavior(optional)

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.

Steps to reproduce the problem(optional)

  1. First I create the habit and change status to success on certain dates (simulator):
    1

  2. I install the app on my real device, open the calendar and statuses on speicfic dates are missing (18):
    img_de5c098a367c-1
    As you can see on my dashboard, there are 7 records and 18th day is there as well..
    image

  3. Even futher, if I add more statuses and reinstall the app then even more of them are missing.
    Example with more statuses going away:
    img_c5073ab15ce8-1
    2

Seems like I am having some problems with syncing. @caiyue1993, any idea? If you need more information about code, let me know.

Zone not found, first sync fail

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.

Add sharing support

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)

Nested frameworks and submission failure

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:

Hangs when there are too many changes

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.

Compilation erros due to private methods

Expected behavior

Compile without errors

Actual behavior(optional)

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

zrzut ekranu 2018-08-23 08 43 18

Steps to reproduce the problem(optional)

Add IceCream 1.5.0 to Podfile, pod install, compile project.
OR
git clone library GitHub repo, pod install in Example folder, compile project

Other info

pod try works without any problems.

Less verbose logging/printing in console

Currently, IceCream is printing 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?

Does IceCream support CKReference & Realm's LinkingObjects?

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?

Does IceCream use the incremental update?

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 to remove CreamAsset from Realm file ?

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 ?

No IceCream debug print statements

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?

Expected behavior

IceCream outputs debug log statements to the console

Actual behavior(optional)

No debug statements are printed

Swift 4.2 support?

Expected behavior

IceCream works with the latest version of Swift!

Actual behavior

IceCream works with Swift 4.0, but not Swift 4.2. These errors occur:

screen shot 2018-09-19 at 10 18 26 pm

Steps to reproduce the problem

Create a new project with Xcode 10 or later, add IceCream as a dependency using CocoaPods, then build.

Note

I can have a PR ready, if desired!

404 on contribution link

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. 😜

Expected behavior

// Please replace this line with your expected behavior.

Actual behavior(optional)

// Please replace this line with the actual behavior.

Steps to reproduce the problem(optional)

// Please provided to steps to reproduce the problem

Reference links(optional)

// Please offer the reference links to us. We appreciate it.

Sync old changes, not only updates

Expected behavior

Sync existing realm data to CloudKit.

Actual behavior(optional)

Objects present in the database before adding Icecream doesn´t sync.

Steps to reproduce the problem(optional)

Create a realm database without Icecream, add and setup Icrecream to your project. Only updates are pushed to the cloud.

CreamAsset uniqueFileName

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 ?

Split CloudKit requests into smaller chunks

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.

Expected behavior

All modified objects are updated in CloudKit.

Actual behavior(optional)

The CloudKit request fails with the error above.

Option for syncing

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.