iCloud synchronization on tvOS - ios

has anybody managed to get iCloud working on tvOS so far?
I am using key-value-storage and it successfully saves everything in iCloud. However, it does not synchronize the data between the iOS-App and the tvOS-App. I am using the same bundle-identifier for both apps.
Has anyone experienced the same issue?

So, it appears that Apple may have an issue here on the tvOS side, because if I follow Apple's instructions on Configuring Common Key-Value Storage for Multiple Apps I can share between and iOS App and a macOS App, but not the tvOS app using exactly the same setup.
Below are my results:
Apple's Instuctions that I used 1st:
So, CloudKit is all about the default Container rather than the App bundle ID directly. So, I setup my Primary iOS app with default container that will become the key-value share container.
Here is my Primary Entitlements file:
I then stored two NSUbiquitousKeyValueStore pairs in the default store and retrieved the values:
NSUbiquitousKeyValueStore.defaultStore().dictionaryRepresentation
So, in my macOS app I enable CloudKit as well, and remove the default container and set it to the Primary iOS apps container. Then in the Entitlements file I manually setup the com.apple.developer.ubiquity-kvstore-identifier to include the Primary App's bundle ID:
Uncheck default container and toggle Primaries:
Here is my Secondary macOS Entitlements file:
Then I run the macOS app and presto, I have the key-value pairs from the primaries default key-value store and retrieved the values easy-peasy:
NSUbiquitousKeyValueStore.defaultStore().dictionaryRepresentation
If I then make the SAME EXACT MODIFICATIONS to my tvOS app, the defaultStore() show as empty and I cannot get it to share with the iOS and macOS app.
Here is my Secondary tsOS Entitlements file:
And no presto, no values:

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.

<Error>: Couldn't read values in CFPrefsPlistSource

I'm facing some problems with iOS 11. We use App Groups to share some information between some of our apps, but some clients after updated their iPhone to iOS 11+ the apps stoped accessing the information in the App Groups. It always worked.
I'm getting following error:
Couldn't read values in CFPrefsPlistSource<0x1c010b5b0> (Domain: group.com.****, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null), Contents Need Refresh: Yes): Using kCFPreferencesAnyUser with a container is only allowed for System Containers, detaching from cfprefsd
Anyone has any idea of what can be causing this? Some clients after delete all apps and install again resolved the problem, but some said that it didn't resolved (I don't know if they really deleted all of our apps).
There is some way to recycle or clean the App Groups?
From watch OS 2 we are not able to access app groups so if you want to get any info from keychain e.g login info or some thing, you can use watch connectivity framework. When I tried to access some information from userdefault which worked fine in watchOS1 it shows me the same error after upgrading watchOS . For how work with watch connectivity please see this link. Here everything is explained.
https://kristina.io/watchos-2-how-to-communicate-between-devices-using-watch-connectivity/
In my case error was caused by the fact, that I was trying to create plist file named "settings.plist" inside of the Shared Container the iOS provides us for access via AppGroup.
Seems like it prevents us to create files with names similar to os & core functionality.
Changing the filename, for example "07087_settings" – removes the error, changing back to "settings" – throws error again.

iOS, config files and sandboxing

My understanding is that because of sandboxing, it isn't possible to view any text file (ie config file) associated with an iOS app using another app. Something quite simple with Android. Am I mistaken?
I am trying to implement a text config file with a Unity iOS app that gets loaded and parsed once when the application boots.
This config file would also be able to be edited and saved manually on that actual iOS device.
(addendum)
In Unity there is PersistentDataPath which resolves to /var/mobile/Container/Data/Application/foo/Documents
Is there an iOS supported file explorer app that will allow me view and edit files in this location (without jailbreaking)?
Use can check iOS App Groups. It allows multiple apps access to shared containers and allow interprocess communication. There is no so much documentation about this, but maybe that's what you're looking for. At least you can share NSUserDefaults between the apps.
NSUserDefaults it's a most simple way to save any (not big) configurations for your app. For manual editing: if your app on the device signed with developer certificate, you can connect through any iOS supported file explorer app and edit it. But after release, from App Store, your app installed in restricted/private path, so it's not possible, if only you don't have a jailbreak.
Initial configuration you can put into your app bundle, and at the first run just copy them to NSUserDefaults.
Short answer: There are utilities such as iExplorer - https://macroplant.com - that allow "file manager" type access. However...
Long answer: If your app requires users to buy (or get) other software to modify configuration files, the chances of Apple approving it are slim to none.
The appropriate thing to do is to provide a User Interface in your own app which allows the user to modify / update the settings.

Unable to get values from settings bundle in watchOS 2

I have a settings bundles that I use with my watch app. I am migrating my app to watchOS 2. Does anyone know how setting bundles are supposed to work? Does the iPhone transfer the values to a the standard user defaults or to a user defaults with a suite name for a shared app group? I can't get either to work and I can't find any documentation on how setting bundles are supposed to work with watchOS 2.
The accepted answer is wrong. You can use Shared App Groups for the Settings bundle on WatchOS 2 and access the values via NSUserDefaults. No Watch Connectivity required. It is just tricky to set up and the official documentation is missing crucial info.
Recently discovered how to do it in my question here.
The 2 important points are:
You need to enable Shared App Groups on all 3 targets (iOS app, Watchkit app, WatchKit extension)
It only works on the real device, not simulator. You might need to remove the app from both devices and reinstall to have it start working.
In Watch OS 2.0 since the Watch App extension is in the Apple Watch (not in the iOS App as in Watch 1.0) you can't transfer data through user defaults, so you should use instead WatchConnectivity.
If you have a settings bundle or a framework and you want to use it in the AW App extension and in the iOS APP, you should import it in every target of your project.

Common iCloud container between Mac and iOS app?

I want to build an iCloud based app that runs on both the Apple platforms, iOS and Mac. The app will use UIDocument on iOS and NSDocument on Mac to have a document based synchronization model - documents created on iOS will be available on Mac and vice versa.
The particular problem I'm facing is that I want the same iCloud container on both the apps. XCode creates a default container for the app based on the App ID, which has to be different on both the apps because this seems to be an Apple requirement - no two apps can have the same app id even if they are on different platforms.
So I left the default created container alone and added another container on both the Mac app as well as the iOS app. The app seems to work fine, I can create a new file package in both the apps in the correct place, but I'm having 2 issues:
The container does not appear properly in the iCloud settings management screen. In the entitlements section in XCode, I named the container as com.mycompany.myapp.mycontainer in both the apps. In the settings screen in iOS (Settings -> General -> Usage -> Manage Storage -> Show All) my app is listed as "mycontainer" instead of the App's actual name as I expected. Is it possible to supply a name and icon in the App's Info.plist to make it list properly?
My NSMetadataQuery is not working properly. I had made the iOS app with the Empty Application template, so the Info.plist was not properly setup with the CFBundleDocumentTypes key but I figured that out and fixed it. For firing my NSMetadataQuery in the iOS app, I'm using:
[self.queryCloud setPredicate:[NSPredicate predicateWithFormat:#"%K like '*.myextension*'",NSMetadataItemFSNameKey]];
with the search scope set like this:
[self.queryCloud setSearchScopes:[NSArray arrayWithObjects:NSMetadataQueryUbiquitousDocumentsScope, NSMetadataQueryUbiquitousDataScope, nil]];
I run the query after establishing the container's URL, I get the started and finished gathering notifications, but never the update notification from the NSMetadataQuery. Unless I go ahead and create a new document. If I create the document then I get notifications for Update, but only in that session. Next time I start up the app, the same settings don't give me any update notifications from NSMetadataQuery.
What am I doing wrong? Any pointers to articles on creating an iCloud document app targeting both Mac and iOS would be much appreciated! Suggestions, thoughts are most welcome.
I don't know about your NSMetadataQuery issues, but adding a shared iCloud container is easy, as long as you get the gotcha:
Pick one app ID that will be your shared cloud container. Doesn't matter if iOS or Mac OS X, you need to publish this app and it must be approved from the Apple Review Team* before your iCloud container will be available to any other app. e.g.
com.company.myawesomeapp
Note that you must not use a container name after your app ID (com.company.myawesomeapp.cloudcontainer), just use your appID!
Pick a second app ID (doesn't really matter), and create your second app. Open up Xcode and enable iCloud in the Capabilites Pane. Then under "iCloud Container Identifiers", add the identifier of your first (published and approved!) app
com.company.myawesomeapp
That's it!
There's just this one catch and that's the bottom line:
In order to use a container, an app must be available and approved. Before approval no other app may access your container, because technically it only exists as soon as your app is approved. Actually, it doesn't have to be available in the AppStore, it just needs to be approved (can be on developer held release).
You can only use a (shared) iCloud container if your app is published and has been approved.

Resources