iOS Couchbase: Shared CBL manager between app and app extension - ios

I'm trying to implement a shared couchbase database between an iOS application and app extension, but there is an issue with consistency between the two targets.
When the application manager deletes the database document in couchbase lite iOS, the app extension manager gets outdated.
Does anyone know how to inform the extension manager about this deletion?
The database is saved in a shared App group.
I've tried to make a pull replication for the database in my extension, which doesn't work as expected.
If I create a new manager every time I read from the database from my extension, it works as expected, but this will create a new thread for every read.
Thank you!

This blog and associated sample app illustrates sharing of data between iOS app and a Today app extension.
There appears to be an issue with replication from within iOS App extensions which is tracked here.

Related

CloudKit + CoreData on iOS and watchOS sync not working

I have a iOS + watchOS app that I want to use the same data model. So I created a CoreData stack and I set up everything for NSPersistentCloudKitContainer.
My iOS app can access the CloudKit container as I can read from the logs in the console, however when my watchOS app wants to connect to the CloudKit container (same iCloud.foo.myID as the iOS app) I get an error saying Invalid bundle ID for container.
I tried several new containers. I also retried to check all checkboxes on the capabilities pane again and again.
Am I missing something?
(I also read Core data + CloudKit - sharing between iOS and watchOS companion app which did not help)
I had same problem. Solution for me was make xcdatamodel shared for both app (in my case it's not standalone app for watch, but extension).
So just check the box for share this model for both app:
Also set class generation to Cathegory/Extension or Manual, because you need a little bit different implementation of entity class for iOS and WatchOS. If someone know how to use one class and checking which OS call the instance it will be perfect.

MacOS - creating Finder Sync Extension with iCloud for iOS/MacOS

This is a very theoretical question, but quiet important for me, how I approach my next steps.
I am developing a SwiftUI MacOS app, where a user can upload own files. The metadata getting stored in CoreData and the file I store manually in the file system. At the moment I am using the default file folder for my application.
Soon I want to have a iCloud sync between my Mac OSX app and my iOS app. I read about it and it should work. CoreData should be no problem.
Now to my question if it will be possible to approach it that way I am thinking of:
I would like to create a Finder Sync Extension for my Mac OSX app, so I get a own folder, which can be added to the favorites and be observed. I want all my local files to be stored there. That should work..
Will I am able to sync these files which are stored in the Finder Sync Extension with iCloud to my iOS app?
Can I create a extension on iOS aswell, to display these files?
I am not storing my documents in a Data blob of the CoreData or allowing External Storage. I store all manually. Will I am able to still sync my documents via iCloud.
All in all, I want to know if I can store my files in the Finder folder, and still keep them synced with iCloud to iOS? If that is not possible, please let me know. Would be interesting to know in forehand.
A Finder Sync Extension should not "do" any syncing. In fact, Apple specifically recommends that a separate background process be used for any networking-like activity:
It’s generally best if the extension focuses on handling the badges, contextual menus, and toolbar buttons. Place in a separate service (a Login Item or Launch Agent) any code that performs the sync, updates state, or communicates with remote data sources. This approach ensures that there is only one syncing service running at a time.
https://developer.apple.com/library/archive/documentation/General/Conceptual/ExtensibilityPG/Finder.html
A Finder Sync Extension is used to provide file badges, menus, and otherwise modify the UI of Finder.
Adding a Finder extension doesn't give you a folder, let alone one that syncs.
You need to provide the folder and all sandbox details related to that. Your main app and/or background process needs to provide the syncing service.
In summary, your main app handles all of the syncing.
The Finder Extension only updates the UI for certain folders. It doesn't provide any syncing itself. So any "syncing with iCloud" question you have should be asked independently of the Finder Sync Extension context.

How to migrate an existing Appcelerator Titanium app database to a native Swift iOS app

I'm about to rebuild an application originally written in Appcelerator's Titanium into a fully native iOS app written in Swift.
The app relies heavily on the SQLite database created using Titanium Alloy Models, whereby users save items into their local database on their phone. I need this data to be accessible when the user updates their app with the newly rebuilt version.
Here are my questions:
Will the database be carried over when the app gets updated?
Can I access the database with the new Swift app?
Can I still create models in the new swift app for the database items?
If I create models in Swift, will they override the tables I created in Titanium? Will the user's data get lost?
Are there a set of best practices for this?
Please note I need to achieve this in Swift - not Objective C
Note, what I'm doing is basically the reverse of this question:
Titanium - Retrieving SQLite Data from previous version of iOS App
Unless you tell it otherwise, Alloy will generate a _alloy_ database at the location documented under Ti.Database.open().
Unless you specify an idAttribute in your model adapter config, Alloy will create an alloy_id UNIQUE TEXT column to store the unique guid for each model.
Apart from that, it's a plain old SQLite database that you can access from Swift.

App Groups and iCloud in iOS

I am familiar with iCloud syncing, but I am new to app groups. There may be a simple answer to this question, but I haven't found it yet. Basically, I have an app in which I have iCloud integration, and now I want to try to add a today extension. I am currently using Core Data as a backend and would like to continue to do so. However, from what I have read, I need to move my data store to a shared location by defining an "App Group". (http://blog.sam-oakley.co.uk/post/92323630293/sharing-core-data-between-app-and-extension-in-ios-8 and Accessing Core Data SQL Database in iOS 8 Extension (Sharing Data Between App and Widget Extension)) I haven't been able to find out if this location is synced using iCloud or not. Or, because I"m using iCloud, do I need an App Group at all? I appreciate any and all help/suggestions.
If you're already using iCloud, you don't need to use app groups, because your extension can access the same iCloud container as your app does. As long as your entitlements and provisioning are configured correctly, you can literally just use the same Core Data stack setup in the extension as in the app.
Apple's Lister demo project does this, but there's nothing special about it. Just use iCloud as usual.
App groups are usually necessary to share data between apps and extensions. But a big exception is when the data is already stored external to the app-- as with iCloud.

When to use SQlite — iOS

I just learned the basics of integrating SQLite3 into an iPhone app, but I still don't really know where or when to use it. Is the SQLite database just locally created on the device or will every app have its own database? If I for example want an app where the user can upload a recipe to the database, will other devices be able to fetch that recipe from the database or do I need something else to make that such of app? Sorry for the noob question but I can't find an answer..
An SQLite database, in iOS, is stored locally. That means that every iOS device has his own independent SQLite database.
Usually, in the case of the recipe you mencioned, you need a backend to sync information with other devices. You can update your SQLite database or just browse the information without a SQLite database behind.
Aditionally, in iOS you have one tool under your belt that it can be used to persist information locally : Core Data. There are some tools that can be used to sync core data information with a server like Parse.
Your app will have its own sqlite database. Your app can have 100 sqlite databases if it wants. It's just a file like any other file your app works with. It will be specific to your app in your app's sandbox. It will not be shared across devices. Just like any other file.
A SQLite database is just a file that you would put in your app's directory, and iOS apps are sandboxed so that one app can't read the files of another app.
If you need to share data from your app, you can have your app implement a URL prefix, and you read the data in your app, but share it using the system defined mechanism. Have a look here, here, and here for more guidance on the subject.

Resources