App Groups and iCloud in iOS - 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.

Related

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.

iOS Couchbase: Shared CBL manager between app and app extension

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.

Access app data on iCloud drive

I'm new to IOS development so this is probably a silly question that is easy to answer.
I have created an IOS App using Core Data and CloudKit. It is successfully syncing with iCloud Drive running on IOS 8.1.1
The app is functioning, and iCloud is syncing the data with multiple devices correctly, but I would like to know how to use a web browser to locate the files that are stored remotely in my iCloud Drive account.
It is not located in the iCloud Drive folder with the data from other IOS applications on www.iCloud.com and although I can find the name of the datastore in the iCloud Container section of my Developer profile, I cannot see how to access it directly from a browser.
Is there a way that I can access the stored data externally to test it for security and also to monitor it's size?
Thanks for your help!
I don't know if you can see it using the web interface. You might be able to use the iCloud browser in Xcode to see the files, but I don't think that works either.
The way I usually do it is to open Terminal, and cd into ~/Library/Mobile Documents, and then into the container for your app. The iCloud data should be in there.
(Note you can't use Finder because it hides all data outside Documents.)

What is the expected lifecycle of iOS 8 App Group directories?

I am starting to investigate iOS 8 extensions, and I see that App Groups are the mechanism provided to pass data between the host app and the extension. This data sharing can be done with NSUserDefaults, flat files, and core data. When you setup an app group, a new directory is created on the device/simulator that is outside the application sandbox. That directory can be accessed from the host app and the extension, and it would appear that other apps from the same account/team can also access this directory.
Given all of this, I would like to know what the lifecycle of the shared App Group directory and its contents are. I have been unable to find any Apple documentation explaining this. Some empirical testing on the simulator has shown that when more than one application is installed that is accessing the app group, the directory is removed when the last application that has that App Group entitlement is removed. This is what I expected to see. I'd like some confirmation that this is the case. Also, is there any potential for the system purging this location under low disc conditions?
I'm trying to determine if it is "safe" to store my app's primary core data database in this App Group location, or if I should be making copies of data there instead. I don't want my main database to get wiped out from underneath me unexpectedly by the system.
Also, what is the intent for App Group directories? Should they be used for sharing data with extensions only, or are they intended as a general data sharing mechanism between apps from the same developer account/team?
I also posted this on the Apple Dev forums, and got an answer back from someone in Apple developer relations. Here is what they said:
Is there any potential for the system purging this location under low disc conditions?
That won't happen.
I'm trying to determine if it is "safe" to store my app's primary core data database in this App Group location, or if I should be making copies of data there instead.
Placing your core data store in an App Group directory is perfectly reasonable.
Also, what is the intent for App Group directories?
They are there so that suites of apps can shared data. I think the clearest expression of this comes from the Mac documentation. The "App Sandbox Design Guide" says:
[...] an application can use the com.apple.security.application-groups entitlement to request access to a shared container that is common to multiple applications produced by the same development team. This container is intended for content that is not user-facing, such as shared caches or databases.
Documentation

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